Still cleaning

This commit is contained in:
tom79 2020-03-07 17:00:21 +01:00
parent 84e832e19c
commit a1121fc6ce
9 changed files with 253 additions and 321 deletions

View File

@ -14,7 +14,6 @@
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
package app.fedilab.android.activities; package app.fedilab.android.activities;
import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -39,6 +38,8 @@ import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout; import com.google.android.material.tabs.TabLayout;
import org.jetbrains.annotations.NotNull;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask; import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
import app.fedilab.android.fragments.DisplayAdminAccountsFragment; import app.fedilab.android.fragments.DisplayAdminAccountsFragment;
@ -63,7 +64,6 @@ public class AdminActivity extends BaseActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
setTheme(R.style.AppAdminTheme); setTheme(R.style.AppAdminTheme);
@ -79,12 +79,7 @@ public class AdminActivity extends BaseActivity {
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close); ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title); TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title);
toolbar_close.setOnClickListener(new View.OnClickListener() { toolbar_close.setOnClickListener(v -> finish());
@Override
public void onClick(View v) {
finish();
}
});
toolbar_title.setText(String.format(getString(R.string.administration) + " %s", Helper.getLiveInstance(getApplicationContext()))); toolbar_title.setText(String.format(getString(R.string.administration) + " %s", Helper.getLiveInstance(getApplicationContext())));
} }
setContentView(R.layout.activity_admin); setContentView(R.layout.activity_admin);
@ -99,76 +94,165 @@ public class AdminActivity extends BaseActivity {
final LinearLayout tabStrip = (LinearLayout) admin_tablayout.getChildAt(0); final LinearLayout tabStrip = (LinearLayout) admin_tablayout.getChildAt(0);
tabStrip.getChildAt(0).setOnLongClickListener(new View.OnLongClickListener() { tabStrip.getChildAt(0).setOnLongClickListener(v -> {
@Override PopupMenu popup = new PopupMenu(AdminActivity.this, tabStrip.getChildAt(0));
public boolean onLongClick(View v) { popup.getMenuInflater()
PopupMenu popup = new PopupMenu(AdminActivity.this, tabStrip.getChildAt(0)); .inflate(R.menu.option_filter_admin_reports, popup.getMenu());
popup.getMenuInflater() Menu menu = popup.getMenu();
.inflate(R.menu.option_filter_admin_reports, popup.getMenu()); final MenuItem itemUnresolved = menu.findItem(R.id.action_unresolved_reports);
Menu menu = popup.getMenu();
final MenuItem itemUnresolved = menu.findItem(R.id.action_unresolved_reports);
itemUnresolved.setChecked(unresolved); itemUnresolved.setChecked(unresolved);
popup.setOnDismissListener(new PopupMenu.OnDismissListener() { popup.setOnDismissListener(menu12 -> {
FragmentTransaction fragTransaction = getSupportFragmentManager().beginTransaction();
fragTransaction.detach(displayAdminReportsFragment);
Bundle bundle = new Bundle();
bundle.putBoolean("unresolved", unresolved);
displayAdminReportsFragment.setArguments(bundle);
fragTransaction.attach(displayAdminReportsFragment);
fragTransaction.commit();
});
popup.setOnMenuItemClickListener(item -> {
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
item.setActionView(new View(getApplicationContext()));
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override @Override
public void onDismiss(PopupMenu menu) { public boolean onMenuItemActionExpand(MenuItem item) {
FragmentTransaction fragTransaction = getSupportFragmentManager().beginTransaction(); return false;
fragTransaction.detach(displayAdminReportsFragment);
Bundle bundle = new Bundle();
bundle.putBoolean("unresolved", unresolved);
displayAdminReportsFragment.setArguments(bundle);
fragTransaction.attach(displayAdminReportsFragment);
fragTransaction.commit();
} }
});
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
item.setActionView(new View(getApplicationContext()));
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
return false;
}
@Override @Override
public boolean onMenuItemActionCollapse(MenuItem item) { public boolean onMenuItemActionCollapse(MenuItem item) {
return false;
}
});
if (item.getItemId() == R.id.action_unresolved_reports) {
unresolved = !unresolved;
}
itemUnresolved.setChecked(unresolved);
return false; return false;
} }
}); });
popup.show(); if (item.getItemId() == R.id.action_unresolved_reports) {
return true; unresolved = !unresolved;
} }
itemUnresolved.setChecked(unresolved);
return false;
});
popup.show();
return true;
}); });
tabStrip.getChildAt(1).setOnLongClickListener(new View.OnLongClickListener() { tabStrip.getChildAt(1).setOnLongClickListener(v -> {
@Override PopupMenu popup = new PopupMenu(AdminActivity.this, tabStrip.getChildAt(1));
public boolean onLongClick(View v) { popup.getMenuInflater()
PopupMenu popup = new PopupMenu(AdminActivity.this, tabStrip.getChildAt(1)); .inflate(R.menu.option_filter_admin_accounts, popup.getMenu());
popup.getMenuInflater() Menu menu = popup.getMenu();
.inflate(R.menu.option_filter_admin_accounts, popup.getMenu()); final MenuItem itemLocal = menu.findItem(R.id.action_local);
Menu menu = popup.getMenu(); final MenuItem itemRemote = menu.findItem(R.id.action_remote);
final MenuItem itemLocal = menu.findItem(R.id.action_local); final MenuItem itemActive = menu.findItem(R.id.action_active);
final MenuItem itemRemote = menu.findItem(R.id.action_remote); final MenuItem itemPending = menu.findItem(R.id.action_pending);
final MenuItem itemActive = menu.findItem(R.id.action_active); final MenuItem itemDisabled = menu.findItem(R.id.action_disabled);
final MenuItem itemPending = menu.findItem(R.id.action_pending); final MenuItem itemSilenced = menu.findItem(R.id.action_silenced);
final MenuItem itemDisabled = menu.findItem(R.id.action_disabled); final MenuItem itemSuspended = menu.findItem(R.id.action_suspended);
final MenuItem itemSilenced = menu.findItem(R.id.action_silenced); if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
final MenuItem itemSuspended = menu.findItem(R.id.action_suspended); itemSilenced.setVisible(false);
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) { itemPending.setVisible(false);
itemSilenced.setVisible(false); itemSuspended.setVisible(false);
itemPending.setVisible(false); }
itemSuspended.setVisible(false);
itemLocal.setChecked(local);
itemRemote.setChecked(remote);
itemActive.setChecked(active);
itemPending.setChecked(pending);
itemDisabled.setChecked(disabled);
itemSilenced.setChecked(silenced);
itemSuspended.setChecked(suspended);
popup.setOnDismissListener(menu1 -> {
FragmentTransaction fragTransaction = getSupportFragmentManager().beginTransaction();
fragTransaction.detach(displayAdminAccountsFragment);
Bundle bundle = new Bundle();
bundle.putBoolean("local", local);
bundle.putBoolean("remote", remote);
bundle.putBoolean("active", active);
bundle.putBoolean("pending", pending);
bundle.putBoolean("disabled", disabled);
bundle.putBoolean("silenced", silenced);
bundle.putBoolean("suspended", suspended);
displayAdminAccountsFragment.setArguments(bundle);
fragTransaction.attach(displayAdminAccountsFragment);
fragTransaction.commit();
});
popup.setOnMenuItemClickListener(item -> {
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
item.setActionView(new View(getApplicationContext()));
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
return false;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
return false;
}
});
switch (item.getItemId()) {
case R.id.action_local:
if (!local) {
remote = false;
local = true;
}
break;
case R.id.action_remote:
if (!remote) {
remote = true;
local = false;
}
break;
case R.id.action_active:
if (!active) {
active = true;
pending = false;
disabled = false;
silenced = false;
suspended = false;
}
break;
case R.id.action_pending:
if (!pending) {
pending = true;
active = false;
disabled = false;
silenced = false;
suspended = false;
}
break;
case R.id.action_disabled:
if (!disabled) {
disabled = true;
active = false;
pending = false;
silenced = false;
suspended = false;
}
break;
case R.id.action_silenced:
if (!silenced) {
silenced = true;
active = false;
pending = false;
disabled = false;
suspended = false;
}
break;
case R.id.action_suspended:
if (!suspended) {
suspended = true;
active = false;
pending = false;
disabled = false;
silenced = false;
}
break;
} }
itemLocal.setChecked(local); itemLocal.setChecked(local);
@ -178,115 +262,10 @@ public class AdminActivity extends BaseActivity {
itemDisabled.setChecked(disabled); itemDisabled.setChecked(disabled);
itemSilenced.setChecked(silenced); itemSilenced.setChecked(silenced);
itemSuspended.setChecked(suspended); itemSuspended.setChecked(suspended);
return false;
popup.setOnDismissListener(new PopupMenu.OnDismissListener() { });
@Override popup.show();
public void onDismiss(PopupMenu menu) { return true;
FragmentTransaction fragTransaction = getSupportFragmentManager().beginTransaction();
fragTransaction.detach(displayAdminAccountsFragment);
Bundle bundle = new Bundle();
bundle.putBoolean("local", local);
bundle.putBoolean("remote", remote);
bundle.putBoolean("active", active);
bundle.putBoolean("pending", pending);
bundle.putBoolean("disabled", disabled);
bundle.putBoolean("silenced", silenced);
bundle.putBoolean("suspended", suspended);
displayAdminAccountsFragment.setArguments(bundle);
fragTransaction.attach(displayAdminAccountsFragment);
fragTransaction.commit();
}
});
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
item.setActionView(new View(getApplicationContext()));
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
return false;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
return false;
}
});
switch (item.getItemId()) {
case R.id.action_local:
if (!local) {
remote = false;
local = true;
}
break;
case R.id.action_remote:
if (!remote) {
remote = true;
local = false;
}
break;
case R.id.action_active:
if (!active) {
active = true;
pending = false;
disabled = false;
silenced = false;
suspended = false;
}
break;
case R.id.action_pending:
if (!pending) {
pending = true;
active = false;
disabled = false;
silenced = false;
suspended = false;
}
break;
case R.id.action_disabled:
if (!disabled) {
disabled = true;
active = false;
pending = false;
silenced = false;
suspended = false;
}
break;
case R.id.action_silenced:
if (!silenced) {
silenced = true;
active = false;
pending = false;
disabled = false;
suspended = false;
}
break;
case R.id.action_suspended:
if (!suspended) {
suspended = true;
active = false;
pending = false;
disabled = false;
silenced = false;
}
break;
}
itemLocal.setChecked(local);
itemRemote.setChecked(remote);
itemActive.setChecked(active);
itemPending.setChecked(pending);
itemDisabled.setChecked(disabled);
itemSilenced.setChecked(silenced);
itemSuspended.setChecked(suspended);
return false;
}
});
popup.show();
return true;
}
}); });
@ -334,33 +313,31 @@ public class AdminActivity extends BaseActivity {
private class AdminPagerAdapter extends FragmentStatePagerAdapter { private class AdminPagerAdapter extends FragmentStatePagerAdapter {
AdminPagerAdapter(FragmentManager fm) { AdminPagerAdapter(FragmentManager fm) {
super(fm); super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
} }
@NotNull
@Override @Override
public Fragment getItem(int position) { public Fragment getItem(int position) {
Bundle bundle = new Bundle(); Bundle bundle;
switch (position) { if (position == 0) {
case 0: displayAdminReportsFragment = new DisplayAdminReportsFragment();
displayAdminReportsFragment = new DisplayAdminReportsFragment(); bundle = new Bundle();
bundle = new Bundle(); bundle.putBoolean("unresolved", unresolved);
bundle.putBoolean("unresolved", unresolved); displayAdminReportsFragment.setArguments(bundle);
displayAdminReportsFragment.setArguments(bundle); return displayAdminReportsFragment;
return displayAdminReportsFragment;
case 1:
displayAdminAccountsFragment = new DisplayAdminAccountsFragment();
bundle = new Bundle();
bundle.putBoolean("local", local);
bundle.putBoolean("remote", remote);
bundle.putBoolean("active", active);
bundle.putBoolean("pending", pending);
bundle.putBoolean("disabled", disabled);
bundle.putBoolean("silenced", silenced);
bundle.putBoolean("suspended", suspended);
displayAdminAccountsFragment.setArguments(bundle);
return displayAdminAccountsFragment;
} }
return null; displayAdminAccountsFragment = new DisplayAdminAccountsFragment();
bundle = new Bundle();
bundle.putBoolean("local", local);
bundle.putBoolean("remote", remote);
bundle.putBoolean("active", active);
bundle.putBoolean("pending", pending);
bundle.putBoolean("disabled", disabled);
bundle.putBoolean("silenced", silenced);
bundle.putBoolean("suspended", suspended);
displayAdminAccountsFragment.setArguments(bundle);
return displayAdminAccountsFragment;
} }
@Override @Override

View File

@ -72,9 +72,6 @@ public class SearchResultTabActivity extends BaseActivity {
case Helper.THEME_LIGHT: case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme_Fedilab); setTheme(R.style.AppTheme_Fedilab);
break; break;
case Helper.THEME_DARK:
setTheme(R.style.AppThemeDark);
break;
case Helper.THEME_BLACK: case Helper.THEME_BLACK:
setTheme(R.style.AppThemeBlack); setTheme(R.style.AppThemeBlack);
break; break;
@ -113,12 +110,7 @@ public class SearchResultTabActivity extends BaseActivity {
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close); ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title); TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title);
toolbar_close.setOnClickListener(new View.OnClickListener() { toolbar_close.setOnClickListener(v -> finish());
@Override
public void onClick(View v) {
finish();
}
});
toolbar_title.setText(search); toolbar_title.setText(search);
} }
setTitle(search); setTitle(search);
@ -198,9 +190,10 @@ public class SearchResultTabActivity extends BaseActivity {
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
ScreenSlidePagerAdapter(FragmentManager fm) { ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm); super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
} }
@NotNull
@Override @Override
public Fragment getItem(int position) { public Fragment getItem(int position) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
@ -223,7 +216,7 @@ public class SearchResultTabActivity extends BaseActivity {
bundle.putSerializable("tag", search); bundle.putSerializable("tag", search);
displayStatusFragment.setArguments(bundle); displayStatusFragment.setArguments(bundle);
return displayStatusFragment; return displayStatusFragment;
case 3: default:
displayStatusFragment = new DisplayStatusFragment(); displayStatusFragment = new DisplayStatusFragment();
bundle = new Bundle(); bundle = new Bundle();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.SEARCH); bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.SEARCH);
@ -231,7 +224,6 @@ public class SearchResultTabActivity extends BaseActivity {
displayStatusFragment.setArguments(bundle); displayStatusFragment.setArguments(bundle);
return displayStatusFragment; return displayStatusFragment;
} }
return null;
} }
@Override @Override

View File

@ -18,7 +18,6 @@ package app.fedilab.android.activities;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
@ -87,16 +86,13 @@ public class SettingsActivity extends BaseActivity {
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close); ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title); TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title);
toolbar_close.setOnClickListener(new View.OnClickListener() { toolbar_close.setOnClickListener(v -> {
@Override if (needRestart) {
public void onClick(View v) { showDialog();
if (needRestart) { } else {
showDialog(); finish();
} else {
finish();
}
} }
}); });
toolbar_title.setText(R.string.settings); toolbar_title.setText(R.string.settings);
} }
@ -161,24 +157,16 @@ public class SettingsActivity extends BaseActivity {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(SettingsActivity.this); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(SettingsActivity.this);
dialogBuilder.setMessage(R.string.restart_message); dialogBuilder.setMessage(R.string.restart_message);
dialogBuilder.setTitle(R.string.apply_changes); dialogBuilder.setTitle(R.string.apply_changes);
dialogBuilder.setPositiveButton(R.string.restart, new DialogInterface.OnClickListener() { dialogBuilder.setPositiveButton(R.string.restart, (dialog, id) -> {
@Override Intent mStartActivity = new Intent(getApplicationContext(), MainActivity.class);
public void onClick(DialogInterface dialog, int id) { int mPendingIntentId = 123456;
Intent mStartActivity = new Intent(getApplicationContext(), MainActivity.class); PendingIntent mPendingIntent = PendingIntent.getActivity(getApplicationContext(), mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
int mPendingIntentId = 123456; AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
PendingIntent mPendingIntent = PendingIntent.getActivity(getApplicationContext(), mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT); assert mgr != null;
AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
assert mgr != null; System.exit(0);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
System.exit(0);
}
});
dialogBuilder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
}); });
dialogBuilder.setNegativeButton(R.string.no, (dialog, id) -> dialog.dismiss());
AlertDialog alertDialog = dialogBuilder.create(); AlertDialog alertDialog = dialogBuilder.create();
alertDialog.setCancelable(false); alertDialog.setCancelable(false);
alertDialog.show(); alertDialog.show();
@ -195,10 +183,10 @@ public class SettingsActivity extends BaseActivity {
} }
} }
private class SettingsPagerAdapter extends FragmentStatePagerAdapter { private static class SettingsPagerAdapter extends FragmentStatePagerAdapter {
SettingsPagerAdapter(FragmentManager fm) { SettingsPagerAdapter(FragmentManager fm) {
super(fm); super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
} }
@NotNull @NotNull

View File

@ -1487,7 +1487,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
ScreenSlidePagerAdapter(FragmentManager fm) { ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm); super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
} }
@NotNull @NotNull

View File

@ -146,62 +146,51 @@ public class SlideMediaActivity extends BaseActivity implements OnDownloadInterf
TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title); TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title);
ImageView media_save = getSupportActionBar().getCustomView().findViewById(R.id.media_save); ImageView media_save = getSupportActionBar().getCustomView().findViewById(R.id.media_save);
ImageView media_share = getSupportActionBar().getCustomView().findViewById(R.id.media_share); ImageView media_share = getSupportActionBar().getCustomView().findViewById(R.id.media_share);
toolbar_close.setOnClickListener(new View.OnClickListener() { toolbar_close.setOnClickListener(v -> finish());
@Override media_save.setOnClickListener(view12 -> {
public void onClick(View v) { int position = mPager.getCurrentItem();
finish(); Attachment attachment = attachments.get(position);
} if( attachment.getType().compareTo("image") == 0 ){
}); if (Build.VERSION.SDK_INT >= 23) {
media_save.setOnClickListener(new View.OnClickListener() { if (ContextCompat.checkSelfPermission(SlideMediaActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(SlideMediaActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
@Override ActivityCompat.requestPermissions(SlideMediaActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE);
public void onClick(View view) {
int position = mPager.getCurrentItem();
Attachment attachment = attachments.get(position);
if( attachment.getType().compareTo("image") == 0 ){
if (Build.VERSION.SDK_INT >= 23) {
if (ContextCompat.checkSelfPermission(SlideMediaActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(SlideMediaActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(SlideMediaActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE);
} else {
Helper.manageMove(SlideMediaActivity.this, attachment.getUrl(), false);
}
} else { } else {
Helper.manageMove(SlideMediaActivity.this, attachment.getUrl(), false); Helper.manageMove(SlideMediaActivity.this, attachment.getUrl(), false);
} }
}else { } else {
if (Build.VERSION.SDK_INT >= 23) { Helper.manageMove(SlideMediaActivity.this, attachment.getUrl(), false);
if (ContextCompat.checkSelfPermission(SlideMediaActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(SlideMediaActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { }
ActivityCompat.requestPermissions(SlideMediaActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE); }else {
} else { if (Build.VERSION.SDK_INT >= 23) {
Helper.manageDownloadsNoPopup(SlideMediaActivity.this, attachment.getUrl()); if (ContextCompat.checkSelfPermission(SlideMediaActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(SlideMediaActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
downloadID = -1; ActivityCompat.requestPermissions(SlideMediaActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE);
}
} else { } else {
Helper.manageDownloadsNoPopup(SlideMediaActivity.this, attachment.getUrl()); Helper.manageDownloadsNoPopup(SlideMediaActivity.this, attachment.getUrl());
downloadID = -1; downloadID = -1;
} }
}
}
});
media_share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int position = mPager.getCurrentItem();
Attachment attachment = attachments.get(position);
if( attachment.getType().compareTo("image") == 0 ){
Helper.manageMove(SlideMediaActivity.this, attachment.getUrl(), true);
}else if (attachment.getType().toLowerCase().equals("video") || attachment.getType().toLowerCase().equals("audio") || attachment.getType().toLowerCase().equals("gifv")) {
downloadID = Helper.manageDownloadsNoPopup(SlideMediaActivity.this, attachment.getUrl());
} else { } else {
if (Build.VERSION.SDK_INT >= 23) { Helper.manageDownloadsNoPopup(SlideMediaActivity.this, attachment.getUrl());
if (ContextCompat.checkSelfPermission(SlideMediaActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(SlideMediaActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { downloadID = -1;
ActivityCompat.requestPermissions(SlideMediaActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE); }
} else { }
downloadID = Helper.manageDownloadsNoPopup(SlideMediaActivity.this, attachment.getUrl());
} });
media_share.setOnClickListener(view1 -> {
int position = mPager.getCurrentItem();
Attachment attachment = attachments.get(position);
if( attachment.getType().compareTo("image") == 0 ){
Helper.manageMove(SlideMediaActivity.this, attachment.getUrl(), true);
}else if (attachment.getType().toLowerCase().equals("video") || attachment.getType().toLowerCase().equals("audio") || attachment.getType().toLowerCase().equals("gifv")) {
downloadID = Helper.manageDownloadsNoPopup(SlideMediaActivity.this, attachment.getUrl());
} else {
if (Build.VERSION.SDK_INT >= 23) {
if (ContextCompat.checkSelfPermission(SlideMediaActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(SlideMediaActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(SlideMediaActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE);
} else { } else {
downloadID = Helper.manageDownloadsNoPopup(SlideMediaActivity.this, attachment.getUrl()); downloadID = Helper.manageDownloadsNoPopup(SlideMediaActivity.this, attachment.getUrl());
} }
} else {
downloadID = Helper.manageDownloadsNoPopup(SlideMediaActivity.this, attachment.getUrl());
} }
} }
}); });
@ -227,12 +216,7 @@ public class SlideMediaActivity extends BaseActivity implements OnDownloadInterf
media_description.setText(description); media_description.setText(description);
media_description.setVisibility(View.VISIBLE); media_description.setVisibility(View.VISIBLE);
handler.postDelayed(new Runnable() { handler.postDelayed(() -> media_description.setVisibility(View.GONE), med_desc_timeout);
@Override
public void run() {
media_description.setVisibility(View.GONE);
}
}, med_desc_timeout);
} else { } else {
media_description.setVisibility(View.GONE); media_description.setVisibility(View.GONE);
@ -254,12 +238,7 @@ public class SlideMediaActivity extends BaseActivity implements OnDownloadInterf
media_description.setText(description); media_description.setText(description);
media_description.setVisibility(View.VISIBLE); media_description.setVisibility(View.VISIBLE);
handler.postDelayed(new Runnable() { handler.postDelayed(() -> media_description.setVisibility(View.GONE), med_desc_timeout);
@Override
public void run() {
media_description.setVisibility(View.GONE);
}
}, med_desc_timeout);
} else { } else {
media_description.setVisibility(View.GONE); media_description.setVisibility(View.GONE);
@ -316,12 +295,7 @@ public class SlideMediaActivity extends BaseActivity implements OnDownloadInterf
media_description.setText(description); media_description.setText(description);
media_description.setVisibility(View.VISIBLE); media_description.setVisibility(View.VISIBLE);
handler.postDelayed(new Runnable() { handler.postDelayed(() -> media_description.setVisibility(View.GONE), med_desc_timeout);
@Override
public void run() {
media_description.setVisibility(View.GONE);
}
}, med_desc_timeout);
} else { } else {
media_description.setVisibility(View.GONE); media_description.setVisibility(View.GONE);
@ -435,7 +409,7 @@ public class SlideMediaActivity extends BaseActivity implements OnDownloadInterf
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
ScreenSlidePagerAdapter(FragmentManager fm) { ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm); super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
} }
@NotNull @NotNull

View File

@ -29,6 +29,8 @@ import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout; import com.google.android.material.tabs.TabLayout;
import org.jetbrains.annotations.NotNull;
import java.util.Objects; import java.util.Objects;
import app.fedilab.android.R; import app.fedilab.android.R;
@ -134,27 +136,26 @@ public class TootInfoActivity extends BaseActivity {
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
ScreenSlidePagerAdapter(FragmentManager fm) { ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm); super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
} }
@NotNull
@Override @Override
public Fragment getItem(int position) { public Fragment getItem(int position) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
switch (position) { if (position == 0) {
case 0: DisplayAccountsFragment displayAccountsFragment = new DisplayAccountsFragment();
DisplayAccountsFragment displayAccountsFragment = new DisplayAccountsFragment(); bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.REBLOGGED);
bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.REBLOGGED); bundle.putString("targetedid", toot_id);
bundle.putString("targetedid", toot_id); displayAccountsFragment.setArguments(bundle);
displayAccountsFragment.setArguments(bundle); return displayAccountsFragment;
return displayAccountsFragment;
case 1:
displayAccountsFragment = new DisplayAccountsFragment();
bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.FAVOURITED);
bundle.putString("targetedid", toot_id);
displayAccountsFragment.setArguments(bundle);
return displayAccountsFragment;
} }
return null; DisplayAccountsFragment displayAccountsFragment;
displayAccountsFragment = new DisplayAccountsFragment();
bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.FAVOURITED);
bundle.putString("targetedid", toot_id);
displayAccountsFragment.setArguments(bundle);
return displayAccountsFragment;
} }

View File

@ -210,7 +210,7 @@ public class TabLayoutNotificationsFragment extends Fragment {
int mNumOfTabs; int mNumOfTabs;
private PagerAdapter(FragmentManager fm, int NumOfTabs) { private PagerAdapter(FragmentManager fm, int NumOfTabs) {
super(fm); super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
this.mNumOfTabs = NumOfTabs; this.mNumOfTabs = NumOfTabs;
} }

View File

@ -86,7 +86,7 @@ public class TabLayoutScheduleFragment extends Fragment {
int mNumOfTabs; int mNumOfTabs;
private PagerAdapter(FragmentManager fm, int NumOfTabs) { private PagerAdapter(FragmentManager fm, int NumOfTabs) {
super(fm); super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
this.mNumOfTabs = NumOfTabs; this.mNumOfTabs = NumOfTabs;
} }

View File

@ -101,7 +101,7 @@ public class TabLayoutTootsFragment extends Fragment {
int mNumOfTabs; int mNumOfTabs;
private PagerAdapter(FragmentManager fm, int NumOfTabs) { private PagerAdapter(FragmentManager fm, int NumOfTabs) {
super(fm); super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
this.mNumOfTabs = NumOfTabs; this.mNumOfTabs = NumOfTabs;
} }