exodus-privacy-android-app/app/src/main/java/org/eu/exodus_privacy/exodusprivacy/MainActivity.java

127 lines
4.5 KiB
Java
Raw Normal View History

2018-02-20 13:54:18 +01:00
/*
* Copyright (C) 2018 Anthony Chomienne, anthony@mob-dev.fr
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.eu.exodus_privacy.exodusprivacy;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
2018-04-14 14:37:51 +02:00
import android.app.SearchManager;
import android.content.Context;
import android.databinding.DataBindingUtil;
2018-02-20 13:54:18 +01:00
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
2018-04-14 14:37:51 +02:00
import android.support.v7.widget.SearchView;
import android.view.Menu;
import android.view.MenuInflater;
2018-02-20 13:54:18 +01:00
import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationListAdapter;
import org.eu.exodus_privacy.exodusprivacy.databinding.MainBinding;
2018-02-20 13:54:18 +01:00
import org.eu.exodus_privacy.exodusprivacy.fragments.AppListFragment;
import org.eu.exodus_privacy.exodusprivacy.fragments.ReportFragment;
import org.eu.exodus_privacy.exodusprivacy.listener.NetworkListener;
public class MainActivity extends AppCompatActivity {
AppListFragment appList;
ReportFragment report;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final MainBinding mainBinding = DataBindingUtil.setContentView(this,R.layout.main);
2018-02-20 13:54:18 +01:00
NetworkListener networkListener = new NetworkListener() {
@Override
public void onSuccess() {
runOnUiThread(() -> {
appList.updateComplete();
if(report != null)
report.updateComplete();
2018-02-20 13:54:18 +01:00
});
}
@Override
public void onError(String error) {
runOnUiThread(() -> {
appList.updateComplete();
Snackbar bar = Snackbar.make(mainBinding.fragmentContainer,error,Snackbar.LENGTH_LONG);
2018-02-20 13:54:18 +01:00
bar.show();
});
}
@Override
public void onProgress(int resourceId, int progress, int maxProgress) {
//do nothing here
}
};
ApplicationListAdapter.OnAppClickListener onAppClickListener = packageInfo -> {
report = ReportFragment.newInstance(getPackageManager(),packageInfo);
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.addToBackStack(null);
transaction.replace(R.id.fragment_container,report);
transaction.commit();
};
appList = AppListFragment.newInstance(networkListener,onAppClickListener);
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.fragment_container,appList);
transaction.commit();
}
@Override
public void onBackPressed() {
super.onBackPressed();
if(report != null)
report = null;
}
2018-04-14 14:37:51 +02:00
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.action_filter).getActionView();
assert searchManager != null;
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
appList.filter(query);
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
appList.filter(newText);
return true;
}
});
return true;
}
2018-02-20 13:54:18 +01:00
}