Fixes a small bad behavior when changing the theme.
This commit is contained in:
parent
920cbd6afa
commit
b6dc5e31a0
|
@ -29,6 +29,7 @@ import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.SearchView;
|
import android.support.v7.widget.SearchView;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.support.design.widget.NavigationView;
|
import android.support.design.widget.NavigationView;
|
||||||
import android.support.v4.view.GravityCompat;
|
import android.support.v4.view.GravityCompat;
|
||||||
|
@ -73,6 +74,7 @@ import fr.gouv.etalab.mastodon.fragments.TabLayoutSettingsFragment;
|
||||||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||||
import mastodon.etalab.gouv.fr.mastodon.R;
|
import mastodon.etalab.gouv.fr.mastodon.R;
|
||||||
|
|
||||||
|
import static fr.gouv.etalab.mastodon.helper.Helper.CHANGE_THEME_INTENT;
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.HOME_TIMELINE_INTENT;
|
import static fr.gouv.etalab.mastodon.helper.Helper.HOME_TIMELINE_INTENT;
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
|
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.NOTIFICATION_INTENT;
|
import static fr.gouv.etalab.mastodon.helper.Helper.NOTIFICATION_INTENT;
|
||||||
|
@ -81,6 +83,7 @@ import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.changeUser;
|
import static fr.gouv.etalab.mastodon.helper.Helper.changeUser;
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.loadPPInActionBar;
|
import static fr.gouv.etalab.mastodon.helper.Helper.loadPPInActionBar;
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.menuAccounts;
|
import static fr.gouv.etalab.mastodon.helper.Helper.menuAccounts;
|
||||||
|
import static fr.gouv.etalab.mastodon.helper.Helper.unCheckAllMenuItems;
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.updateHeaderAccountInfo;
|
import static fr.gouv.etalab.mastodon.helper.Helper.updateHeaderAccountInfo;
|
||||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||||
|
|
||||||
|
@ -335,17 +338,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void unCheckAllMenuItems(@NonNull final Menu menu) {
|
|
||||||
int size = menu.size();
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
final MenuItem item = menu.getItem(i);
|
|
||||||
if(item.hasSubMenu()) {
|
|
||||||
unCheckAllMenuItems(item.getSubMenu());
|
|
||||||
} else {
|
|
||||||
item.setChecked(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -372,18 +365,20 @@ public class MainActivity extends AppCompatActivity
|
||||||
final NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
|
final NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
|
||||||
userIdIntent = extras.getString(PREF_KEY_ID); //Id of the account in the intent
|
userIdIntent = extras.getString(PREF_KEY_ID); //Id of the account in the intent
|
||||||
if (extras.getInt(INTENT_ACTION) == NOTIFICATION_INTENT){
|
if (extras.getInt(INTENT_ACTION) == NOTIFICATION_INTENT){
|
||||||
changeUser(MainActivity.this, userIdIntent, false); //Connects the account which is related to the notification
|
|
||||||
unCheckAllMenuItems(navigationView.getMenu());
|
unCheckAllMenuItems(navigationView.getMenu());
|
||||||
navigationView.getMenu().performIdentifierAction(R.id.nav_notification, 0);
|
changeUser(MainActivity.this, userIdIntent, false); //Connects the account which is related to the notification
|
||||||
if( navigationView.getMenu().findItem(R.id.nav_notification) != null)
|
tabLayout.getTabAt(3).select();
|
||||||
navigationView.getMenu().findItem(R.id.nav_notification).setChecked(true);
|
|
||||||
matchingIntent = true;
|
matchingIntent = true;
|
||||||
}else if( extras.getInt(INTENT_ACTION) == HOME_TIMELINE_INTENT){
|
}else if( extras.getInt(INTENT_ACTION) == HOME_TIMELINE_INTENT){
|
||||||
changeUser(MainActivity.this, userIdIntent, false); //Connects the account which is related to the notification
|
|
||||||
unCheckAllMenuItems(navigationView.getMenu());
|
unCheckAllMenuItems(navigationView.getMenu());
|
||||||
navigationView.getMenu().performIdentifierAction(R.id.nav_home, 0);
|
changeUser(MainActivity.this, userIdIntent, false); //Connects the account which is related to the notification
|
||||||
if( navigationView.getMenu().findItem(R.id.nav_home) != null)
|
tabLayout.getTabAt(0).select();
|
||||||
navigationView.getMenu().findItem(R.id.nav_home).setChecked(true);
|
matchingIntent = true;
|
||||||
|
}else if( extras.getInt(INTENT_ACTION) == CHANGE_THEME_INTENT){
|
||||||
|
unCheckAllMenuItems(navigationView.getMenu());
|
||||||
|
navigationView.setCheckedItem(R.id.nav_settings);
|
||||||
|
navigationView.getMenu().performIdentifierAction(R.id.nav_settings, 0);
|
||||||
|
toolbarTitle.setText(R.string.settings);
|
||||||
matchingIntent = true;
|
matchingIntent = true;
|
||||||
}
|
}
|
||||||
}else if( Intent.ACTION_SEND.equals(action) && type != null ){
|
}else if( Intent.ACTION_SEND.equals(action) && type != null ){
|
||||||
|
|
|
@ -142,6 +142,10 @@ public class WebviewActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUrl(String newUrl){
|
||||||
|
this.url = newUrl;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy(){
|
public void onDestroy(){
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
|
|
@ -36,10 +36,15 @@ import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||||
import mastodon.etalab.gouv.fr.mastodon.R;
|
import mastodon.etalab.gouv.fr.mastodon.R;
|
||||||
|
|
||||||
import static android.app.Activity.RESULT_OK;
|
import static android.app.Activity.RESULT_OK;
|
||||||
|
import static fr.gouv.etalab.mastodon.helper.Helper.CHANGE_THEME_INTENT;
|
||||||
|
import static fr.gouv.etalab.mastodon.helper.Helper.HOME_TIMELINE_INTENT;
|
||||||
|
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -201,6 +206,10 @@ public class SettingsFragment extends Fragment {
|
||||||
getActivity().setTheme(R.style.AppTheme);
|
getActivity().setTheme(R.style.AppTheme);
|
||||||
}
|
}
|
||||||
getActivity().recreate();
|
getActivity().recreate();
|
||||||
|
Intent intent = new Intent(context, MainActivity.class);
|
||||||
|
intent.putExtra(INTENT_ACTION, CHANGE_THEME_INTENT);
|
||||||
|
startActivity(intent);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.design.widget.NavigationView;
|
import android.support.design.widget.NavigationView;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.support.v4.app.NotificationManagerCompat;
|
import android.support.v4.app.NotificationManagerCompat;
|
||||||
|
@ -56,6 +57,7 @@ import android.text.method.LinkMovementMethod;
|
||||||
import android.text.style.ClickableSpan;
|
import android.text.style.ClickableSpan;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.SubMenu;
|
import android.view.SubMenu;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -168,7 +170,7 @@ public class Helper {
|
||||||
//Notifications
|
//Notifications
|
||||||
public static final int NOTIFICATION_INTENT = 1;
|
public static final int NOTIFICATION_INTENT = 1;
|
||||||
public static final int HOME_TIMELINE_INTENT = 2;
|
public static final int HOME_TIMELINE_INTENT = 2;
|
||||||
|
public static final int CHANGE_THEME_INTENT = 3;
|
||||||
//Settings
|
//Settings
|
||||||
public static final String SET_TOOTS_PER_PAGE = "set_toots_per_page";
|
public static final String SET_TOOTS_PER_PAGE = "set_toots_per_page";
|
||||||
public static final String SET_ACCOUNTS_PER_PAGE = "set_accounts_per_page";
|
public static final String SET_ACCOUNTS_PER_PAGE = "set_accounts_per_page";
|
||||||
|
@ -1311,4 +1313,16 @@ public class Helper {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void unCheckAllMenuItems(@NonNull final Menu menu) {
|
||||||
|
int size = menu.size();
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
final MenuItem item = menu.getItem(i);
|
||||||
|
if(item.hasSubMenu()) {
|
||||||
|
unCheckAllMenuItems(item.getSubMenu());
|
||||||
|
} else {
|
||||||
|
item.setChecked(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@ import android.view.View;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.webkit.WebViewClient;
|
import android.webkit.WebViewClient;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import fr.gouv.etalab.mastodon.activities.WebviewActivity;
|
||||||
import mastodon.etalab.gouv.fr.mastodon.R;
|
import mastodon.etalab.gouv.fr.mastodon.R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,7 +59,12 @@ public class MastalabWebViewClient extends WebViewClient {
|
||||||
}else {
|
}else {
|
||||||
activity.setTitle(url);
|
activity.setTitle(url);
|
||||||
}
|
}
|
||||||
|
//Changes the url in webview activity so that it can be opened with an external app
|
||||||
|
try{
|
||||||
|
if( activity instanceof WebviewActivity)
|
||||||
|
((WebviewActivity)activity).setUrl(url);
|
||||||
|
}catch (Exception ignore){}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue