Fixes crashes when removing tabs + compact mode as default theme

This commit is contained in:
stom79 2018-09-08 12:58:08 +02:00
parent 079c8473c4
commit 00298dd312
14 changed files with 71 additions and 56 deletions

View File

@ -947,7 +947,7 @@ public abstract class BaseMainActivity extends BaseActivity
}
public void refreshSearchTab(){
Helper.addSearchTag(BaseMainActivity.this, tabLayout, adapter);
Helper.refreshSearchTag(BaseMainActivity.this, tabLayout, adapter);
}
public void removeSearchTab(String tag){

View File

@ -335,7 +335,7 @@ public class InstanceFederatedActivity extends BaseActivity {
});
refreshInstanceTab();
Helper.refreshInstanceTab(InstanceFederatedActivity.this, tabLayout, adapter);
int tabCount = tabLayout.getTabCount();
for( int j = 0 ; j < tabCount ; j++){
@ -376,9 +376,6 @@ public class InstanceFederatedActivity extends BaseActivity {
// LocalBroadcastManager.getInstance(this).registerReceiver(receive_data, new IntentFilter(Helper.RECEIVE_DATA));
}
public void refreshInstanceTab(){
Helper.addInstanceTab(InstanceFederatedActivity.this, tabLayout, adapter);
}
@Override

View File

@ -14,12 +14,15 @@ package fr.gouv.etalab.mastodon.activities;
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
* see <http://www.gnu.org/licenses>. */
import android.app.Application;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.StrictMode;
import com.evernote.android.job.JobManager;
import org.acra.ACRA;
import org.acra.BuildConfig;
import org.acra.annotation.AcraDialog;
import org.acra.annotation.AcraMailSender;
import org.acra.config.CoreConfigurationBuilder;
import org.acra.config.LimiterConfigurationBuilder;
@ -51,7 +54,12 @@ public class MainApplication extends Application{
StrictMode.setVmPolicy(builder.build());
CoreConfigurationBuilder ACRABuilder = new CoreConfigurationBuilder(this);
ACRABuilder.setBuildConfigClass(BuildConfig.class).setReportFormat(StringFormat.KEY_VALUE_LIST);
ACRABuilder.getPluginConfigurationBuilder(MailSenderConfigurationBuilder.class).setMailTo("support@mastalab.app").setSubject("Bug report for Mastalab").setEnabled(true);
String version = "";
try {
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
version = pInfo.versionName;
} catch (PackageManager.NameNotFoundException ignored) { }
ACRABuilder.getPluginConfigurationBuilder(MailSenderConfigurationBuilder.class).setReportAsFile(false).setMailTo("support@mastalab.app").setSubject(" Crash Report for Mastalab " + version).setEnabled(true);
ACRABuilder.getPluginConfigurationBuilder(LimiterConfigurationBuilder.class).setEnabled(true);
ACRA.init(this, ACRABuilder);
}

View File

@ -471,7 +471,7 @@ public class Status implements Parcelable{
return;
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false);
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, true);
int mode;
if( isCompactMode)
mode = Html.FROM_HTML_MODE_COMPACT;
@ -503,7 +503,7 @@ public class Status implements Parcelable{
if( (status.getReblog() != null && status.getReblog().getContent() == null) || (status.getReblog() == null && status.getContent() == null))
return;
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false);
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, true);
int mode;
if( isCompactMode)
mode = Html.FROM_HTML_MODE_COMPACT;
@ -626,7 +626,7 @@ public class Status implements Parcelable{
return;
SpannableString spannableStringTranslated = null;
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false);
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, true);
int mode;
if( isCompactMode)
mode = Html.FROM_HTML_MODE_COMPACT;
@ -735,7 +735,7 @@ public class Status implements Parcelable{
spannableString.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, (theme==Helper.THEME_DARK||theme==Helper.THEME_BLACK)?R.color.mastodonC2:R.color.mastodonC4)), matchStart, matchEnd,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false);
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, true);
int mode;
if( isCompactMode)
mode = Html.FROM_HTML_MODE_COMPACT;

View File

@ -380,7 +380,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
status = statuses.get(position);
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false);
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, true);
int HIDDEN_STATUS = 0;
String filter;
if( type == RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS)
@ -560,6 +560,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
holder.status_more.getLayoutParams().width = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context);
holder.status_privacy.getLayoutParams().height = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context);
holder.status_privacy.getLayoutParams().width = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context);
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, true);
@ -619,6 +620,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
changeDrawableColor(context, holder.status_privacy, R.color.dark_icon);
changeDrawableColor(context, R.drawable.ic_repeat,R.color.dark_icon);
changeDrawableColor(context, R.drawable.ic_star_border,R.color.dark_icon);
changeDrawableColor(context, R.drawable.ic_plus_one,R.color.dark_icon);
changeDrawableColor(context, R.drawable.ic_pin_drop, R.color.dark_icon);
changeDrawableColor(context, R.drawable.ic_photo,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_remove_red_eye,R.color.dark_text);
@ -635,6 +637,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
changeDrawableColor(context, holder.status_more, R.color.black);
changeDrawableColor(context, holder.status_privacy, R.color.black);
changeDrawableColor(context, R.drawable.ic_repeat,R.color.black);
changeDrawableColor(context, R.drawable.ic_plus_one,R.color.black);
changeDrawableColor(context, R.drawable.ic_star_border,R.color.black);
changeDrawableColor(context, R.drawable.ic_pin_drop, R.color.black);
changeDrawableColor(context, R.drawable.ic_photo,R.color.mastodonC4);
@ -665,6 +668,9 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
if( !status.isEmojiFound())
status.makeEmojis(context, StatusListAdapter.this);
holder.status_content.setText(status.getContentSpan(), TextView.BufferType.SPANNABLE);
holder.status_spoiler.setText(status.getContentSpanCW(), TextView.BufferType.SPANNABLE);
holder.status_account_displayname.setText(status.getDisplayNameSpan(), TextView.BufferType.SPANNABLE);
@ -1013,9 +1019,13 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
holder.status_favorite_count.setCompoundDrawables(imgFav, null, null, null);
holder.status_reblog_count.setCompoundDrawables(imgReblog, null, null, null);
holder.status_reply.setCompoundDrawables(imgReply, null, null, null);
if(getItemViewType(position) != FOCUSED_STATUS && isCompactMode && ((status.getReblog() == null && status.getReplies_count() > 0) || (status.getReblog() != null && status.getReblog().getReplies_count() > 0))){
Drawable img = context.getResources().getDrawable( R.drawable.ic_plus_one );
holder.status_reply.setCompoundDrawablesWithIntrinsicBounds( imgReply, null, img, null);
}else{
holder.status_reply.setCompoundDrawablesWithIntrinsicBounds( imgReply, null, null, null);
}
boolean isOwner = status.getAccount().getId().equals(userId);
// Pinning toots is only available on Mastodon 1._6_.0 instances.
@ -1310,7 +1320,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
builderInner.setMessage(Html.fromHtml(status.getContent()));
break;
case R.id.action_open_browser:
Helper.openBrowser(context, status.getUrl());
Helper.openBrowser(context, status.getReblog()!=null?status.getReblog().getUrl():status.getUrl());
return true;
case R.id.action_remove:
builderInner = new AlertDialog.Builder(context);

View File

@ -277,7 +277,7 @@ public class SettingsFragment extends Fragment {
}
});
boolean compact_mode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false);
boolean compact_mode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, true);
final CheckBox set_compact_mode = rootView.findViewById(R.id.set_compact_mode);
set_compact_mode.setChecked(compact_mode);

View File

@ -2180,7 +2180,7 @@ public class Helper {
public static void addInstanceTab(Context context, TabLayout tableLayout, InstanceFederatedActivity.PagerAdapter pagerAdapter){
public static void refreshInstanceTab(Context context, TabLayout tableLayout, InstanceFederatedActivity.PagerAdapter pagerAdapter){
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
new InstancesDAO(context, db).cleanDoublon();
List<String> instances = new InstancesDAO(context, db).getAllInstances();
@ -2200,42 +2200,27 @@ public class Helper {
}
}
public static void removeInstanceTab(String keyword, TabLayout tableLayout, InstanceFederatedActivity.PagerAdapter pagerAdapter){
int selection = -1;
for(int i = 0; i < tableLayout.getTabCount() ; i++ ){
if( tableLayout.getTabAt(i).getText() != null && tableLayout.getTabAt(i).getText().equals(keyword)) {
selection = i;
break;
}
}
if( selection != -1)
removeTab(tableLayout, pagerAdapter, selection);
}
public static void removeTab(TabLayout tableLayout, InstanceFederatedActivity.PagerAdapter pagerAdapter, int position) {
if (tableLayout.getTabCount() >= position ) {
if(tableLayout.getTabCount() > 0)
tableLayout.removeTabAt(position);
pagerAdapter.removeTabPage();
}
}
public static void removeTab(TabLayout tableLayout, BaseMainActivity.PagerAdapter pagerAdapter, int position) {
if (tableLayout.getTabCount() >= position ) {
if(tableLayout.getTabCount() > 0)
tableLayout.removeTabAt(position);
pagerAdapter.removeTabPage();
}
}
public static void addTab(TabLayout tableLayout, InstanceFederatedActivity.PagerAdapter pagerAdapter, String title) {
tableLayout.addTab(tableLayout.newTab().setText(title));
pagerAdapter.addTabPage(title);
}
public static void removeTab(TabLayout tableLayout, InstanceFederatedActivity.PagerAdapter pagerAdapter, int position) {
if (tableLayout.getTabCount() >= position ) {
try {
pagerAdapter.removeTabPage();
if(tableLayout.getTabCount() > 0)
tableLayout.removeTabAt(position);
}catch (Exception ignored){
refreshInstanceTab(tableLayout.getContext(), tableLayout, pagerAdapter);
}
}
}
public static void addSearchTag(Context context, TabLayout tableLayout, BaseMainActivity.PagerAdapter pagerAdapter){
public static void refreshSearchTag(Context context, TabLayout tableLayout, BaseMainActivity.PagerAdapter pagerAdapter){
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
List<String> searches = new SearchDAO(context, db).getAllSearch();
int countInitialTab = ((BaseMainActivity) context).countPage;
@ -2257,6 +2242,20 @@ public class Helper {
}
}
public static void removeTab(TabLayout tableLayout, BaseMainActivity.PagerAdapter pagerAdapter, int position) {
if (tableLayout.getTabCount() >= position ) {
try {
if(tableLayout.getTabCount() > 0)
tableLayout.removeTabAt(position);
pagerAdapter.removeTabPage();
}catch (Exception ignored){
refreshSearchTag(tableLayout.getContext(), tableLayout, pagerAdapter);
}
}
}
public static void removeSearchTag(String keyword, TabLayout tableLayout, BaseMainActivity.PagerAdapter pagerAdapter){
int selection = -1;

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

View File

@ -1,6 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_translate"
android:title="@string/translate"
app:showAsAction="never" />
<item
android:id="@+id/action_bookmark"
android:title="@string/bookmark_add"
app:showAsAction="never" />
<item
android:id="@+id/action_open_browser"
android:title="@string/action_open_in_web"
app:showAsAction="never"/>
<item
android:id="@+id/action_mute"
android:title="@string/more_action_1"
@ -37,16 +49,5 @@
android:id="@+id/action_mention"
android:title="@string/more_action_7"
app:showAsAction="never" />
<item
android:id="@+id/action_bookmark"
android:title="@string/bookmark_add"
app:showAsAction="never" />
<item
android:id="@+id/action_open_browser"
android:title="@string/action_open_in_web"
app:showAsAction="never"/>
<item
android:id="@+id/action_translate"
android:title="@string/translate"
app:showAsAction="never" />
</menu>