正在查看: FMG v6.0 应用的 MainActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: FMG v6.0 应用的 MainActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package it.icontact.android.pdf2ipad.irisfmg.view.main;
import android.animation.Animator;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.google.firebase.messaging.Constants;
import com.karumi.dexter.Dexter;
import com.karumi.dexter.listener.single.BasePermissionListener;
import icepick.Icepick;
import it.icontact.android.pdf2ipad.irisfmg.App;
import it.icontact.android.pdf2ipad.irisfmg.R;
import it.icontact.android.pdf2ipad.irisfmg.R2;
import it.icontact.android.pdf2ipad.irisfmg.files.FileManagerPDFs;
import it.icontact.android.pdf2ipad.irisfmg.model.Categoria;
import it.icontact.android.pdf2ipad.irisfmg.model.DBUpdater;
import it.icontact.android.pdf2ipad.irisfmg.model.Documento;
import it.icontact.android.pdf2ipad.irisfmg.model.DocumentoDAO;
import it.icontact.android.pdf2ipad.irisfmg.model.StatisticaEntryUtils;
import it.icontact.android.pdf2ipad.irisfmg.utils.ui.AnimatorUtils;
import it.icontact.android.pdf2ipad.irisfmg.utils.ui.PopupSelector;
import it.icontact.android.pdf2ipad.irisfmg.view.documento.DocumentoActivity;
import it.icontact.android.pdf2ipad.irisfmg.view.finder.FinderActivity;
import it.icontact.android.pdf2ipad.irisfmg.view.main.DocumentiAdapter;
import it.icontact.android.pdf2ipad.irisfmg.view.notifiche.NotificheFragment;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import timber.log.Timber;
public class MainActivity extends AppCompatActivity implements DocumentiAdapter.ActionsListener {
private static final long DB_UPDATE_INTERVAL_MS = 1800000;
private static final long SPLASH_DURATION_MS = 3000;
private static final long SPLASH_FADE_OUT_DURATION_MS = 500;
private static long dbUpdateLast;
private CategorieAdapter adapter;
@BindView(R2.id.categorie_list)
RecyclerView categorieList;
@BindView(R2.id.drawer)
DrawerLayout drawer;
@BindView(R2.id.filter_documenti_online_offline)
TextView filterDocumentiOnlineOffline;
@BindView(R2.id.notifications_button)
View notificationsButton;
@BindView(R2.id.refresh)
SwipeRefreshLayout refreshLayout;
@BindView(R2.id.splash)
View splash;
private boolean filterDocumentiTextIsShort = false;
boolean filterDocumentiOfflineEnabled = false;
int openAfterDownloadDocumentoID = -1;
boolean drawerWasOpen = false;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Icepick.restoreInstanceState(this, savedInstanceState);
ButterKnife.bind(this);
boolean z = false;
this.splash.setVisibility(0);
this.splash.setAlpha(1.0f);
this.filterDocumentiTextIsShort = StringUtils.equalsAny(this.filterDocumentiOnlineOffline.getText(), new CharSequence[]{getString(R.string.ONLINE_CATALOGS_SHORT), getString(R.string.OFFLINE_CATALOGS_SHORT)});
this.drawer.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
@Override
public void onDrawerSlide(final View drawerView, final float offset) {
MainActivity.this.onDrawerSlide(offset);
}
});
CategorieAdapter categorieAdapter = new CategorieAdapter(this);
this.adapter = categorieAdapter;
this.categorieList.setAdapter(categorieAdapter);
this.categorieList.setLayoutManager(new LinearLayoutManager(this));
MainActivityViewModel mainActivityViewModel = (MainActivityViewModel) ViewModelProviders.of(this).get(MainActivityViewModel.class);
mainActivityViewModel.getCategorie().observe(this, new Observer<List<Categoria>>() {
@Override
public void onChanged(final List<Categoria> categorie) {
if (categorie != null) {
MainActivity.this.adapter.setCategorie(categorie);
}
if (new Date().getTime() > MainActivity.dbUpdateLast + MainActivity.DB_UPDATE_INTERVAL_MS) {
StatisticaEntryUtils.insert(MainActivity.this, 1, "Apro il programma");
MainActivity mainActivity = MainActivity.this;
mainActivity.dbUpdate(mainActivity.adapter.getItemCount() > 0);
}
}
});
mainActivityViewModel.getDocumenti().observe(this, new Observer<List<DocumentoDAO.DocumentoWithCountNotifiche>>() {
@Override
public void onChanged(final List<DocumentoDAO.DocumentoWithCountNotifiche> documenti) {
MainActivity.this.adapter.setDocumenti(documenti);
}
});
applyOfflineFilter();
this.refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
MainActivity.this.dbUpdate(false);
}
});
if (getIntent() != null && (getIntent().getFlags() & 1048576) != 0) {
z = true;
}
if (!z) {
elaboraNotificaPush(getIntent());
}
if (Build.VERSION.SDK_INT >= 33) {
Dexter.withActivity(this).withPermission("android.permission.POST_NOTIFICATIONS").withListener(new BasePermissionListener() {
}).check();
}
}
@Override
protected void onStart() {
boolean isBackgrounded = ((App) getApplication()).isBackgrounded();
super.onStart();
EventBus.getDefault().register(this);
if (isBackgrounded) {
this.splash.clearAnimation();
this.splash.setVisibility(0);
this.splash.setAlpha(1.0f);
this.splash.animate().alpha(0.0f).setListener(new AnimatorUtils.Listener() {
@Override
public void onAnimationEnd(final Animator animation) {
MainActivity.this.splash.setVisibility(8);
}
}).setStartDelay(SPLASH_DURATION_MS).start();
} else {
this.splash.setVisibility(8);
}
this.adapter.notifyDataSetChanged();
((App) getApplication()).analyticsSendScreen("HOME PAGE");
}
@Override
protected void onNewIntent(final Intent intent) {
super.onNewIntent(intent);
elaboraNotificaPush(intent);
}
public void dbUpdate(final boolean silent) {
dbUpdateLast = new Date().getTime();
new DBUpdater(this, silent).execute(new Void[0]);
Object[] objArr = new Object[1];
objArr[0] = silent ? "(silent)" : "";
Timber.v("DB update request %s", objArr);
}
public void scrollToAndOpenDocument(final Documento documento) {
this.adapter.scrollToDocumento(this.categorieList, documento);
if (FileManagerPDFs.get(this).getFileState(documento) == FileManagerPDFs.State.AVAILABLE) {
onDocumentoOpenRequest(documento);
} else {
onDocumentoDownloadRequest(documento);
}
}
@Override
public void onDocumentoOpenRequest(final Documento documento) {
this.openAfterDownloadDocumentoID = -1;
DocumentoActivity.startActivity(this, documento);
Timber.w("Opening #%d: %s", new Object[]{Integer.valueOf(documento.id), documento.nome});
}
@Override
public void onDocumentoDownloadRequest(final Documento documento) {
this.openAfterDownloadDocumentoID = documento.id;
FileManagerPDFs.get(this).startDownload(this, documento);
}
@Override
public void onDocumentoDownloadCancelRequest(final Documento documento) {
FileManagerPDFs.get(this).cancelDownload(documento);
}
@Override
public void onDocumentoDeletePDFRequest(final Documento documento) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.SURE_DELETE_ONE);
builder.setPositiveButton(R.string.DELETE, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
FileManagerPDFs.get(MainActivity.this).deleteDocumentoPDF(documento);
}
});
builder.setNegativeButton(R.string.CANCEL, (DialogInterface.OnClickListener) null);
builder.show();
}
@OnClick({R2.id.offline_management_button})
void offlineManagement() {
final FileManagerPDFs fileManagerPDFs = FileManagerPDFs.get(this);
new PopupSelector(this, fileManagerPDFs.hasRunningDownloads() ? new int[]{R.string.DOWNLOAD_ALL, R.string.CLEAR_OFFLINE_DATA_BTN, R.string.STOP_ALL_DOWNLOADINGS} : new int[]{R.string.DOWNLOAD_ALL, R.string.CLEAR_OFFLINE_DATA_BTN}, new PopupSelector.Listener() {
@Override
public void onSelected(final PopupSelector.Choice selected, final int position) {
if (selected.resID == 2131558420) {
MainActivity.this.downloadAllDocumenti();
return;
}
if (selected.resID == 2131558404) {
MainActivity.this.refreshLayout.setRefreshing(false);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle(R.string.SURE_DELETE_ALL_TTL);
builder.setMessage(R.string.SURE_DELETE_ALL_MSG);
builder.setPositiveButton(R.string.CLEAR_OFFLINE_DATA_SHORT_BTN, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
fileManagerPDFs.deleteAllDocumentoPDF();
MainActivity.this.adapter.notifyDataSetChanged();
}
});
builder.setNegativeButton(R.string.CANCEL, (DialogInterface.OnClickListener) null);
builder.show();
return;
}
if (selected.resID == 2131558449) {
fileManagerPDFs.cancelAllDownloads();
}
}
@Override
public void onCancel() {
MainActivity.this.refreshLayout.setRefreshing(false);
}
}).setTitle(getString(R.string.MANAGE_MENU_TTL)).show();
}
public void downloadAllDocumenti() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.SURE_DOWNLOAD_ALL_TTL);
builder.setMessage(R.string.SURE_DOWNLOAD_ALL_MSG);
builder.setPositiveButton(R.string.DOWNLOAD_ALL_SHORT, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
MainActivity.this.openAfterDownloadDocumentoID = -1;
FileManagerPDFs fileManagerPDFs = FileManagerPDFs.get(MainActivity.this);
Iterator<DocumentoDAO.DocumentoWithCountNotifiche> it2 = MainActivity.this.adapter.getDocumenti().iterator();
while (it2.hasNext()) {
fileManagerPDFs.startDownload(MainActivity.this, it2.next());
}
}
});
builder.setNegativeButton(R.string.CANCEL, (DialogInterface.OnClickListener) null);
builder.show();
}
@OnClick({R2.id.filter_documenti_online_offline})
void filterDocumentiToggle() {
this.filterDocumentiOfflineEnabled = !this.filterDocumentiOfflineEnabled;
applyOfflineFilter();
}
private void applyOfflineFilter() {
this.adapter.setOfflineFilter(this.filterDocumentiOfflineEnabled);
if (this.filterDocumentiTextIsShort) {
this.filterDocumentiOnlineOffline.setText(this.filterDocumentiOfflineEnabled ? R.string.OFFLINE_CATALOGS_SHORT : R.string.ONLINE_CATALOGS_SHORT);
} else {
this.filterDocumentiOnlineOffline.setText(this.filterDocumentiOfflineEnabled ? R.string.OFFLINE_CATALOGS : R.string.ONLINE_CATALOGS);
}
}
@OnClick({R2.id.finder_button})
void finderButton() {
startActivity(new Intent(this, (Class<?>) FinderActivity.class));
}
@OnClick({R2.id.notifications_button})
void notificationsButton() {
if (this.drawer.isDrawerOpen(5)) {
this.drawer.closeDrawer(5);
} else {
this.drawer.openDrawer(5);
}
}
public void onDrawerSlide(final float offset) {
Fragment findFragmentById = getSupportFragmentManager().findFragmentById(R.id.sidebar_right);
double d = offset;
if (d > 0.05d) {
if (findFragmentById == null) {
getSupportFragmentManager().beginTransaction().replace(R.id.sidebar_right, NotificheFragment.newInstance()).commitNow();
}
} else {
if (d >= 0.05d || findFragmentById == null) {
return;
}
getSupportFragmentManager().beginTransaction().remove(findFragmentById).commitNow();
}
}
public void closeDrawer() {
this.drawer.closeDrawer(5);
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onDBUpdaterEventStarted(final DBUpdater.Events.Started event) {
if (event.silent) {
return;
}
this.refreshLayout.setRefreshing(true);
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onDBUpdaterEventCompleted(final DBUpdater.Events.Completed event) {
if (event.silent) {
return;
}
this.refreshLayout.setRefreshing(false);
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onDBUpdaterEventSuccess(final DBUpdater.Events.Success event) {
if (event.changedDati) {
return;
}
this.adapter.notifyDataSetChanged();
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onDBUpdaterEventError(final DBUpdater.Events.Error event) {
if (event.silent) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(event.errorMessageRes);
builder.setPositiveButton(R.string.DISMISS, (DialogInterface.OnClickListener) null);
builder.show();
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onPDFFileStateChanged(final FileManagerPDFs.FileStateChanged event) {
this.adapter.notifyDataSetChanged();
if (this.openAfterDownloadDocumentoID == event.documento.id && FileManagerPDFs.get(this).getFileState(event.documento) == FileManagerPDFs.State.AVAILABLE) {
onDocumentoOpenRequest(event.documento);
}
}
private void elaboraNotificaPush(final Intent intent) {
if (intent.hasExtra(Constants.MessagePayloadKeys.MSGID)) {
intent.removeExtra(Constants.MessagePayloadKeys.MSGID);
dbUpdate(false);
this.drawer.post(new Runnable() {
@Override
public void run() {
if (MainActivity.this.drawer.isDrawerOpen(5)) {
return;
}
MainActivity.this.drawer.openDrawer(5);
}
});
}
}
@Override
protected void onStop() {
super.onStop();
EventBus.getDefault().unregister(this);
}
@Override
protected void onSaveInstanceState(final Bundle outState) {
super.onSaveInstanceState(outState);
this.drawerWasOpen = this.drawer.isDrawerOpen(5);
Icepick.saveInstanceState(this, outState);
}
@Override
public void onBackPressed() {
if (this.drawer.isDrawerOpen(5)) {
this.drawer.closeDrawer(5);
} else {
super.onBackPressed();
}
}
}