mirror of
https://github.com/gsantner/dandelion
synced 2024-11-22 12:22:08 +01:00
Added some documentation to MainActivity
This commit is contained in:
parent
160ed992df
commit
68d299f894
1 changed files with 95 additions and 17 deletions
|
@ -163,7 +163,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
customTabActivityHelper.setConnectionCallback(this);
|
customTabActivityHelper.setConnectionCallback(this);
|
||||||
|
|
||||||
fm = getSupportFragmentManager();
|
fm = getSupportFragmentManager();
|
||||||
setupUI(savedInstanceState);
|
setupUI();
|
||||||
|
|
||||||
brOpenExternalLink = new OpenExternalLinkReceiver(this);
|
brOpenExternalLink = new OpenExternalLinkReceiver(this);
|
||||||
brSetTitle = new UpdateTitleReceiver(app, urls, new UpdateTitleReceiver.TitleCallback() {
|
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()");
|
AppLog.i(this, "setupUI()");
|
||||||
|
|
||||||
// Setup toolbar
|
// Setup toolbar
|
||||||
|
@ -244,7 +248,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
/**
|
/**
|
||||||
* Get an instance of the CustomFragment with the tag fragmentTag.
|
* 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 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
|
* @param fragmentTag tag
|
||||||
* @return corresponding Fragment
|
* @return corresponding Fragment
|
||||||
*/
|
*/
|
||||||
|
@ -294,6 +298,9 @@ public class MainActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the navigation slider
|
||||||
|
*/
|
||||||
private void setupNavigationSlider() {
|
private void setupNavigationSlider() {
|
||||||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
||||||
this, navDrawer, toolbarTop, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
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());
|
navMenu.findItem(R.id.nav_public).setVisible(appSettings.isVisibleInNavPublic_activities());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forward toolbar clicks to onNavigationItemSelected
|
||||||
|
* @param view selected view
|
||||||
|
*/
|
||||||
@OnClick(R.id.main__topbar)
|
@OnClick(R.id.main__topbar)
|
||||||
public void onToolBarClicked(View view) {
|
public void onToolBarClicked(View view) {
|
||||||
AppLog.i(this, "onToolBarClicked()");
|
AppLog.i(this, "onToolBarClicked()");
|
||||||
onNavigationItemSelected(navView.getMenu().findItem(R.id.nav_stream));
|
onNavigationItemSelected(navView.getMenu().findItem(R.id.nav_stream));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forward incoming intents to handleIntent()
|
||||||
|
* @param intent incoming
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onNewIntent(Intent intent) {
|
protected void onNewIntent(Intent intent) {
|
||||||
super.onNewIntent(intent);
|
super.onNewIntent(intent);
|
||||||
|
|
||||||
handleIntent(intent);
|
handleIntent(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle intents and execute intent specific actions
|
||||||
|
* @param intent intent to get handled
|
||||||
|
*/
|
||||||
private void handleIntent(Intent intent) {
|
private void handleIntent(Intent intent) {
|
||||||
AppLog.i(this, "handleIntent()");
|
AppLog.i(this, "handleIntent()");
|
||||||
if (intent == null) {
|
if (intent == null) {
|
||||||
|
@ -420,7 +438,8 @@ public class MainActivity extends AppCompatActivity
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
|
} 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) {
|
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
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
AppLog.v(this, "onActivityResult(): "+requestCode);
|
AppLog.v(this, "onActivityResult(): "+requestCode);
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
* Return the fragment which is currently displayed in R.id.fragment_container
|
||||||
AppLog.v(this, "onSaveInstanceState()");
|
* @return top fragment or null if there is none displayed
|
||||||
super.onSaveInstanceState(outState);
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
|
|
||||||
AppLog.v(this, "onRestoreInstanceState()");
|
|
||||||
super.onRestoreInstanceState(savedInstanceState);
|
|
||||||
}
|
|
||||||
|
|
||||||
private CustomFragment getTopFragment() {
|
private CustomFragment getTopFragment() {
|
||||||
Fragment top = fm.findFragmentById(R.id.fragment_container);
|
Fragment top = fm.findFragmentById(R.id.fragment_container);
|
||||||
if(top != null) {
|
if(top != null) {
|
||||||
|
@ -455,6 +472,9 @@ public class MainActivity extends AppCompatActivity
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle presses on the back button
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
AppLog.v(this, "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));
|
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
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
AppLog.v(this, "onCreateOptionsMenu()");
|
AppLog.v(this, "onCreateOptionsMenu()");
|
||||||
|
@ -540,6 +566,11 @@ public class MainActivity extends AppCompatActivity
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the notification and messages counter in the top toolbar
|
||||||
|
* @param menu menu
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||||
MenuItem item;
|
MenuItem item;
|
||||||
|
@ -556,6 +587,11 @@ public class MainActivity extends AppCompatActivity
|
||||||
return super.onPrepareOptionsMenu(menu);
|
return super.onPrepareOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle clicks on the optionsmenu
|
||||||
|
* @param item item
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
AppLog.i(this, "onOptionsItemSelected()");
|
AppLog.i(this, "onOptionsItemSelected()");
|
||||||
|
@ -649,18 +685,30 @@ public class MainActivity extends AppCompatActivity
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the profile name in the navigation slider
|
||||||
|
* @param name name
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onUserProfileNameChanged(String name) {
|
public void onUserProfileNameChanged(String name) {
|
||||||
AppLog.i(this, "onUserProfileNameChanged()");
|
AppLog.i(this, "onUserProfileNameChanged()");
|
||||||
navheaderTitle.setText(name);
|
navheaderTitle.setText(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the profile picture in the navigation slider
|
||||||
|
* @param avatarUrl url of the new profile pic
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onUserProfileAvatarChanged(String avatarUrl) {
|
public void onUserProfileAvatarChanged(String avatarUrl) {
|
||||||
AppLog.i(this, "onUserProfileAvatarChanged()");
|
AppLog.i(this, "onUserProfileAvatarChanged()");
|
||||||
app.getAvatarImageLoader().startImageDownload(navheaderImage, avatarUrl);
|
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) {
|
private void handleHashtag(Intent intent) {
|
||||||
AppLog.v(this, "handleHashtag()");
|
AppLog.v(this, "handleHashtag()");
|
||||||
try {
|
try {
|
||||||
|
@ -671,6 +719,10 @@ public class MainActivity extends AppCompatActivity
|
||||||
openDiasporaUrl(urls.getNewPostUrl());
|
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) {
|
private void handleSendText(Intent intent) {
|
||||||
AppLog.v(this, "handleSendText()");
|
AppLog.v(this, "handleSendText()");
|
||||||
try {
|
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
|
//TODO: Implement some day
|
||||||
private void handleSendImage(Intent intent) {
|
private void handleSendImage(Intent intent) {
|
||||||
AppLog.i(this, "handleSendImage()");
|
AppLog.i(this, "handleSendImage()");
|
||||||
|
@ -737,6 +793,10 @@ public class MainActivity extends AppCompatActivity
|
||||||
Toast.makeText(this, "Not yet implemented.", Toast.LENGTH_SHORT).show();
|
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
|
@Override
|
||||||
public void onNotificationCountChanged(int notificationCount) {
|
public void onNotificationCountChanged(int notificationCount) {
|
||||||
AppLog.i(this, "onNotificationCountChanged()");
|
AppLog.i(this, "onNotificationCountChanged()");
|
||||||
|
@ -744,6 +804,10 @@ public class MainActivity extends AppCompatActivity
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invalidate the top toolbar to update the unread messages counter
|
||||||
|
* @param unreadMessageCount new unread messages count
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onUnreadMessageCountChanged(int unreadMessageCount) {
|
public void onUnreadMessageCountChanged(int unreadMessageCount) {
|
||||||
AppLog.i(this, "onUnreadMessageCountChanged()");
|
AppLog.i(this, "onUnreadMessageCountChanged()");
|
||||||
|
@ -872,6 +936,12 @@ public class MainActivity extends AppCompatActivity
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* React to results of requestPermission
|
||||||
|
* @param requestCode resCode
|
||||||
|
* @param permissions requested permissions
|
||||||
|
* @param grantResults granted results
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||||
switch (requestCode) {
|
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() {
|
public String getTextToBeShared() {
|
||||||
return textToBeShared;
|
return textToBeShared;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the string that will be shared into the new-post-editor
|
||||||
|
* @param textToBeShared
|
||||||
|
*/
|
||||||
public void setTextToBeShared(String textToBeShared) {
|
public void setTextToBeShared(String textToBeShared) {
|
||||||
this.textToBeShared = textToBeShared;
|
this.textToBeShared = textToBeShared;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue