1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-12-22 19:08:03 +01:00

Added some documentation to MainActivity

This commit is contained in:
vanitasvitae 2016-10-02 22:22:08 +02:00
parent 160ed992df
commit 68d299f894

View file

@ -163,7 +163,7 @@ public class MainActivity extends AppCompatActivity
customTabActivityHelper.setConnectionCallback(this);
fm = getSupportFragmentManager();
setupUI(savedInstanceState);
setupUI();
brOpenExternalLink = new OpenExternalLinkReceiver(this);
brSetTitle = new UpdateTitleReceiver(app, urls, new UpdateTitleReceiver.TitleCallback() {
@ -193,7 +193,11 @@ public class MainActivity extends AppCompatActivity
}
}
private void setupUI(Bundle savedInstanceState) {
/**
* Setup the user interface. Set up both toolbars and initialize the snackbars.
* Initialize the navigation drawer and apply intellihide settings.
*/
private void setupUI() {
AppLog.i(this, "setupUI()");
// Setup toolbar
@ -244,7 +248,7 @@ public class MainActivity extends AppCompatActivity
/**
* Get an instance of the CustomFragment with the tag fragmentTag.
* If there was no instance so far, create a new one and add it to the FragmentManagers pool.
* If there is no Fragment with the corresponding Tag, return null.
* If there is no Fragment with the corresponding Tag, return the top fragment.
* @param fragmentTag tag
* @return corresponding Fragment
*/
@ -294,6 +298,9 @@ public class MainActivity extends AppCompatActivity
}
}
/**
* Initialize the navigation slider
*/
private void setupNavigationSlider() {
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, navDrawer, toolbarTop, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
@ -358,19 +365,30 @@ public class MainActivity extends AppCompatActivity
navMenu.findItem(R.id.nav_public).setVisible(appSettings.isVisibleInNavPublic_activities());
}
/**
* Forward toolbar clicks to onNavigationItemSelected
* @param view selected view
*/
@OnClick(R.id.main__topbar)
public void onToolBarClicked(View view) {
AppLog.i(this, "onToolBarClicked()");
onNavigationItemSelected(navView.getMenu().findItem(R.id.nav_stream));
}
/**
* Forward incoming intents to handleIntent()
* @param intent incoming
*/
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
handleIntent(intent);
}
/**
* Handle intents and execute intent specific actions
* @param intent intent to get handled
*/
private void handleIntent(Intent intent) {
AppLog.i(this, "handleIntent()");
if (intent == null) {
@ -420,7 +438,8 @@ public class MainActivity extends AppCompatActivity
break;
}
} else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
//TODO: Implement and add filter to manifest
/* TODO: Implement and add filter to manifest */
return;
}
if (loadUrl != null) {
@ -429,24 +448,22 @@ public class MainActivity extends AppCompatActivity
}
}
/**
* Handle activity results
* @param requestCode reqCode
* @param resultCode resCode
* @param data data
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
AppLog.v(this, "onActivityResult(): "+requestCode);
super.onActivityResult(requestCode, resultCode, data);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
AppLog.v(this, "onSaveInstanceState()");
super.onSaveInstanceState(outState);
}
@Override
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
AppLog.v(this, "onRestoreInstanceState()");
super.onRestoreInstanceState(savedInstanceState);
}
/**
* Return the fragment which is currently displayed in R.id.fragment_container
* @return top fragment or null if there is none displayed
*/
private CustomFragment getTopFragment() {
Fragment top = fm.findFragmentById(R.id.fragment_container);
if(top != null) {
@ -455,6 +472,9 @@ public class MainActivity extends AppCompatActivity
return null;
}
/**
* Handle presses on the back button
*/
@Override
public void onBackPressed() {
AppLog.v(this, "onBackPressed()");
@ -515,6 +535,12 @@ public class MainActivity extends AppCompatActivity
LocalBroadcastManager.getInstance(this).registerReceiver(brOpenExternalLink, new IntentFilter(ACTION_OPEN_EXTERNAL_URL));
}
/**
* Clear and repopulate top and bottom toolbar.
* Also add menu items of the displayed fragment
* @param menu top toolbar
* @return boolean
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
AppLog.v(this, "onCreateOptionsMenu()");
@ -540,6 +566,11 @@ public class MainActivity extends AppCompatActivity
return true;
}
/**
* Set the notification and messages counter in the top toolbar
* @param menu menu
* @return boolean
*/
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem item;
@ -556,6 +587,11 @@ public class MainActivity extends AppCompatActivity
return super.onPrepareOptionsMenu(menu);
}
/**
* Handle clicks on the optionsmenu
* @param item item
* @return boolean
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
AppLog.i(this, "onOptionsItemSelected()");
@ -649,18 +685,30 @@ public class MainActivity extends AppCompatActivity
return super.onOptionsItemSelected(item);
}
/**
* Update the profile name in the navigation slider
* @param name name
*/
@Override
public void onUserProfileNameChanged(String name) {
AppLog.i(this, "onUserProfileNameChanged()");
navheaderTitle.setText(name);
}
/**
* Update the profile picture in the navigation slider
* @param avatarUrl url of the new profile pic
*/
@Override
public void onUserProfileAvatarChanged(String avatarUrl) {
AppLog.i(this, "onUserProfileAvatarChanged()");
app.getAvatarImageLoader().startImageDownload(navheaderImage, avatarUrl);
}
/**
* Handle hashtag clicks. Open the new-post-url and inject the clicked hashtag into the post-editor
* @param intent intent
*/
private void handleHashtag(Intent intent) {
AppLog.v(this, "handleHashtag()");
try {
@ -671,6 +719,10 @@ public class MainActivity extends AppCompatActivity
openDiasporaUrl(urls.getNewPostUrl());
}
/**
* Open the new-post-url and inject text that was shared into the app into the post editors text field
* @param intent shareTextIntent
*/
private void handleSendText(Intent intent) {
AppLog.v(this, "handleSendText()");
try {
@ -725,6 +777,10 @@ public class MainActivity extends AppCompatActivity
}
}
/**
* Share an image shared to the app via diaspora
* @param intent shareImageIntent
*/
//TODO: Implement some day
private void handleSendImage(Intent intent) {
AppLog.i(this, "handleSendImage()");
@ -737,6 +793,10 @@ public class MainActivity extends AppCompatActivity
Toast.makeText(this, "Not yet implemented.", Toast.LENGTH_SHORT).show();
}
/**
* Invalidate the top toolbar to update the notification counter
* @param notificationCount new notification count
*/
@Override
public void onNotificationCountChanged(int notificationCount) {
AppLog.i(this, "onNotificationCountChanged()");
@ -744,6 +804,10 @@ public class MainActivity extends AppCompatActivity
invalidateOptionsMenu();
}
/**
* Invalidate the top toolbar to update the unread messages counter
* @param unreadMessageCount new unread messages count
*/
@Override
public void onUnreadMessageCountChanged(int unreadMessageCount) {
AppLog.i(this, "onUnreadMessageCountChanged()");
@ -872,6 +936,12 @@ public class MainActivity extends AppCompatActivity
return true;
}
/**
* React to results of requestPermission
* @param requestCode resCode
* @param permissions requested permissions
* @param grantResults granted results
*/
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
@ -891,10 +961,18 @@ public class MainActivity extends AppCompatActivity
}
}
/**
* Return the string that will be shared into the new-post-editor
* @return String
*/
public String getTextToBeShared() {
return textToBeShared;
}
/**
* Set the string that will be shared into the new-post-editor
* @param textToBeShared
*/
public void setTextToBeShared(String textToBeShared) {
this.textToBeShared = textToBeShared;
}