Created
January 26, 2019 17:28
-
-
Save barron9/2edfce6e085ce7e9b18f4495929b6754 to your computer and use it in GitHub Desktop.
dashboardactivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.generalmobile.app.gmfilemanager.dashboard; | |
import android.Manifest; | |
import android.app.Activity; | |
import android.app.SearchManager; | |
import android.content.ActivityNotFoundException; | |
import android.content.BroadcastReceiver; | |
import android.content.ComponentName; | |
import android.content.Context; | |
import android.content.DialogInterface; | |
import android.content.Intent; | |
import android.content.IntentFilter; | |
import android.content.SharedPreferences; | |
import android.content.pm.PackageManager; | |
import android.content.res.Configuration; | |
import android.graphics.Color; | |
import android.graphics.drawable.ColorDrawable; | |
import android.graphics.drawable.Drawable; | |
import android.hardware.usb.UsbManager; | |
import android.net.ConnectivityManager; | |
import android.net.Uri; | |
import android.os.Bundle; | |
import android.preference.PreferenceManager; | |
import android.support.annotation.NonNull; | |
import android.support.design.widget.Snackbar; | |
import android.support.v4.app.ActivityCompat; | |
import android.support.v4.content.ContextCompat; | |
import android.support.v4.view.MenuItemCompat; | |
import android.support.v4.widget.DrawerLayout; | |
import android.support.v4.widget.NestedScrollView; | |
import android.support.v7.app.AlertDialog; | |
import android.support.v7.app.AppCompatDelegate; | |
import android.support.v7.widget.CardView; | |
import android.support.v7.widget.DividerItemDecoration; | |
import android.support.v7.widget.LinearLayoutManager; | |
import android.support.v7.widget.RecyclerView; | |
import android.support.v7.widget.SearchView; | |
import android.support.v7.widget.StaggeredGridLayoutManager; | |
import android.support.v7.widget.Toolbar; | |
import android.support.v7.widget.helper.ItemTouchHelper; | |
import android.view.LayoutInflater; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.FrameLayout; | |
import android.widget.ImageView; | |
import android.widget.LinearLayout; | |
import android.widget.RatingBar; | |
import android.widget.RelativeLayout; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
import com.dropbox.core.v2.team.IncludeMembersArg; | |
import com.generalmobile.app.gmfilemanager.BuildConfig; | |
import com.generalmobile.app.gmfilemanager.GmFileManagerApplication; | |
import com.generalmobile.app.gmfilemanager.R; | |
import com.generalmobile.app.gmfilemanager.about.AboutView; | |
import com.generalmobile.app.gmfilemanager.adapters.CategoryAdapter; | |
import com.generalmobile.app.gmfilemanager.adapters.DataSourceAdapter; | |
import com.generalmobile.app.gmfilemanager.adapters.NewAdapter; | |
import com.generalmobile.app.gmfilemanager.analyse.AnalyseActivity; | |
import com.generalmobile.app.gmfilemanager.cloudlist.CloudListActivity; | |
import com.generalmobile.app.gmfilemanager.core.AnalyticsConstants; | |
import com.generalmobile.app.gmfilemanager.core.CategoryNames; | |
import com.generalmobile.app.gmfilemanager.core.DataSourceType; | |
import com.generalmobile.app.gmfilemanager.core.listeners.OnItemClickListener; | |
import com.generalmobile.app.gmfilemanager.core.services.MediaTrackerService; | |
import com.generalmobile.app.gmfilemanager.db.Category; | |
import com.generalmobile.app.gmfilemanager.explorer.ExplorerActivity; | |
import com.generalmobile.app.gmfilemanager.fileserver.FileServerActivity; | |
import com.generalmobile.app.gmfilemanager.imean.ui.login.iMeanLoginActivity; | |
import com.generalmobile.app.gmfilemanager.job.LowStorageDailyJob; | |
import com.generalmobile.app.gmfilemanager.models.DataSourceInfo; | |
import com.generalmobile.app.gmfilemanager.models.News; | |
import com.generalmobile.app.gmfilemanager.newcategory.NewCategoryActivity; | |
import com.generalmobile.app.gmfilemanager.preference.SettingsActivity; | |
import com.generalmobile.app.gmfilemanager.utils.BaseActivity; | |
import com.generalmobile.app.gmfilemanager.utils.UsbUtils; | |
import com.generalmobile.app.gmfilemanager.utils.ui.CategoryCallBack; | |
import com.generalmobile.library.common.feedback.FeedbackActivity; | |
import com.generalmobile.library.common.share.ShareActivity; | |
import com.google.firebase.appindexing.FirebaseAppIndex; | |
import com.google.firebase.appindexing.Indexable; | |
import com.google.firebase.appindexing.builders.Indexables; | |
import com.pixplicity.easyprefs.library.Prefs; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Locale; | |
import javax.inject.Inject; | |
import butterknife.BindView; | |
import butterknife.ButterKnife; | |
import timber.log.Timber; | |
public class DashboardActivity extends BaseActivity implements IDashboardView, SearchView.OnQueryTextListener, OnItemClickListener, View.OnClickListener, DrawerLayout.DrawerListener { | |
public static final String QUERY_KEY = "query"; | |
public static final String UPDATE_ACTION = "com.generalmobile.app.gmfilemanager.dashboard.UPDATE_ACTION"; | |
public static final String UPDATE_CLOUD_ACTION = "com.generalmobile.app.gmfilemanager.dashboard.UPDATE_CLOUD_ACTION"; | |
@BindView(R.id.categoryRecyclerView) | |
RecyclerView categoryRecyclerView; | |
@BindView(R.id.searchView) | |
SearchView searchView; | |
@BindView(R.id.toolbar) | |
Toolbar toolbar; | |
@BindView(R.id.addNewCategoryButton) | |
Button addNewCategoryButton; | |
@BindView(R.id.analyseButton) | |
Button analyseButton; | |
@BindView(R.id.dataSourceRecyclerView) | |
RecyclerView dataSourceRecyclerView; | |
@BindView(R.id.activity_dashboard_drawer) | |
DrawerLayout activityDashboardDrawer; | |
@BindView(R.id.showMoreTextView) | |
TextView showMoreTextView; | |
@BindView(R.id.showMoreLayout) | |
FrameLayout showMoreLayout; | |
@BindView(R.id.addCloud) | |
RelativeLayout addCloudButton; | |
@BindView(R.id.arrowImageView) | |
ImageView arrowImageView; | |
@BindView(R.id.categoryLinearLayout) | |
LinearLayout categoryLinearLayout; | |
@BindView(R.id.cloudLayout) | |
RelativeLayout cloudLayout; | |
@BindView(R.id.showMoreInnerLayout) | |
LinearLayout showMoreInnerLayout; | |
@BindView(R.id.nestedScroolView) | |
NestedScrollView nestedScrollView; | |
@BindView(R.id.card_view) | |
CardView cardView; | |
@BindView(R.id.txtMemoryStatus) | |
TextView txtMemoryStatus; | |
@BindView(R.id.txtQuickCategories) | |
TextView txtQuickCatoggories; | |
@BindView(R.id.memoryStatusLayout) | |
RelativeLayout memoryStatusLayout; | |
@Inject | |
SharedPreferences preferences; | |
private StaggeredGridLayoutManager staggeredGridLayoutManager; | |
private LinearLayoutManager linearLayoutManager; | |
private IDashboardPresenter dashboardPresenter; | |
private DataSourceAdapter dataSourceAdapter; | |
private CategoryAdapter categoryAdapter; | |
private int categoryLayoutHeight; | |
private BroadcastReceiver otgReceiver; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
AppCompatDelegate.setDefaultNightMode( | |
AppCompatDelegate.MODE_NIGHT_AUTO); | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_dashboard); | |
ButterKnife.bind(this); | |
dashboardPresenter = new DashboardPresenter(this); | |
((GmFileManagerApplication) getApplication()).getApplicationComponent().inject(this); | |
super.createMenu(toolbar, activityDashboardDrawer, this); | |
setSupportActionBar(toolbar); | |
checkPermissions(); | |
parseIntent(); | |
otgReceiver = new BroadcastReceiver() { | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
((BaseActivity) DashboardActivity.this).fillLocalStorageRecycler(); | |
dashboardPresenter.getDataSources(); | |
Toast.makeText(context, R.string.usb_device_removed, Toast.LENGTH_SHORT).show(); | |
} | |
}; | |
checkIsFrequentUser(); | |
showWhatsNew(); | |
initDark(); | |
initToolbar(); | |
startService(new Intent(this, MediaTrackerService.class)); | |
LowStorageDailyJob.schedule(); | |
/*nestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() { | |
@Override | |
public void onScrollChange(NestedScrollView nestedScrollView, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { | |
if(oldScrollY < scrollY +50){ | |
cardView.setVisibility(View.VISIBLE); | |
}else{ | |
cardView.setVisibility(View.GONE); | |
} | |
} | |
});*/ | |
} | |
private void initToolbar() { | |
} | |
private void initDark() { | |
String theme = Prefs.getString("app_theme", this.getString(R.string.theme_yellow)); | |
if(this.getString(R.string.dark_theme).equals(theme)){ | |
addCloudButton.setBackground(ContextCompat.getDrawable(this,R.drawable.relative_layout_cloud_dark_bg)); | |
analyseButton.setBackground(ContextCompat.getDrawable(this,R.drawable.dashboard_button_card_dark_bg)); | |
analyseButton.setTextColor(ContextCompat.getColor(this,R.color.darkThemeTextColor)); | |
Drawable imgZoom = this.getResources().getDrawable(R.drawable.ic_zoom_in_black_dark_24dp ); | |
Drawable imgModify = this.getResources().getDrawable(R.drawable.ic_wrap_text_black_dark_24dp ); | |
analyseButton.setCompoundDrawablesWithIntrinsicBounds(imgZoom,null,null,null); | |
addNewCategoryButton.setBackground(ContextCompat.getDrawable(this,R.drawable.dashboard_button_dark_bg)); | |
addNewCategoryButton.setTextColor(ContextCompat.getColor(this,R.color.darkThemeTextColor)); | |
addNewCategoryButton.setCompoundDrawablesWithIntrinsicBounds(imgModify,null,null,null); | |
cloudLayout.setBackgroundDrawable(ContextCompat.getDrawable(this,R.drawable.relative_layout_dark_bg)); | |
showMoreInnerLayout.setBackground(ContextCompat.getDrawable(this,R.drawable.show_more_dark_bg)); | |
txtMemoryStatus.setTextColor(ContextCompat.getColor(this,R.color.darkThemeTextColor)); | |
txtQuickCatoggories.setTextColor(ContextCompat.getColor(this,R.color.darkThemeTextColor)); | |
} | |
else { | |
addCloudButton.setBackground(ContextCompat.getDrawable(this,R.drawable.relative_layout_cloud_bg)); | |
analyseButton.setBackground(ContextCompat.getDrawable(this,R.drawable.dashboard_button_card_bg)); | |
addNewCategoryButton.setBackground(ContextCompat.getDrawable(this,R.drawable.dashboard_button_bg)); | |
cloudLayout.setBackgroundDrawable(ContextCompat.getDrawable(this,R.drawable.relative_layout_bg)); | |
showMoreInnerLayout.setBackground(ContextCompat.getDrawable(this,R.drawable.show_more_bg)); | |
} | |
} | |
private void showWhatsNew() { | |
int version = BuildConfig.VERSION_CODE; | |
int prefVersion = preferences.getInt("version_code", 0); | |
if (version != prefVersion) { | |
showVersionNew(version); | |
preferences.edit().putInt("version_code", version).apply(); | |
} | |
} | |
@Override | |
protected void onPause() { | |
super.onPause(); | |
} | |
private void showVersionNew(int version) { | |
if (version == 222) { | |
View view = LayoutInflater.from(this).inflate(R.layout.dialog_whats_new, null); | |
RecyclerView feature = (RecyclerView) view.findViewById(R.id.featuresRecycler); | |
RecyclerView bugs = (RecyclerView) view.findViewById(R.id.bugsRecycler); | |
LinearLayout rateLayout = (LinearLayout) view.findViewById(R.id.rateLayout); | |
LinearLayout okLayout = (LinearLayout) view.findViewById(R.id.okLayout); | |
TextView titleText = (TextView) view.findViewById(R.id.versionTitle); | |
titleText.setText(getString(R.string.generic_new_dialog_title, BuildConfig.VERSION_NAME, getString(R.string.improvements))); | |
List<News> features = new ArrayList<>(); | |
features.add(new News(getString(R.string.feature_one))); | |
feature.setAdapter(new NewAdapter(features)); | |
List<News> bugsList = new ArrayList<>(); | |
bugsList.add(new News(getString(R.string.bug_one))); | |
bugs.setAdapter(new NewAdapter(bugsList)); | |
AlertDialog.Builder builder = new AlertDialog.Builder(this).setView(view); | |
final AlertDialog dialog = builder.create(); | |
if (dialog.getWindow() != null) { | |
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); | |
} | |
dialog.show(); | |
okLayout.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
dialog.dismiss(); | |
} | |
}); | |
rateLayout.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
dialog.dismiss(); | |
rateApp(); | |
} | |
}); | |
} else { | |
Timber.e("Bu versiyon için değişiklik girilmedi."); | |
} | |
} | |
private void parseIntent() { | |
Intent intent = getIntent(); | |
String path = intent.getStringExtra("path"); | |
String category = intent.getStringExtra("category"); | |
startExplorerWithPath(path, category); | |
} | |
private void startExplorerWithPath(String path, String category) { | |
if (path != null && !path.isEmpty()) { | |
GmFileManagerApplication.getInstance().trackEvent(AnalyticsConstants.SCREEN_EVENT, "OpenFromShortCut", "Uygulama kısayoldan açılıyor : " + path); | |
Intent exp = new Intent(this, ExplorerActivity.class); | |
exp.putExtra("path", path); | |
exp.putExtra("isShortCut", true); | |
startActivity(exp); | |
} else if (category != null && !category.isEmpty()) { | |
GmFileManagerApplication.getInstance().trackEvent(AnalyticsConstants.SCREEN_EVENT, "OpenFromShortCut", "Kategori kısayoldan açılıyor : " + path); | |
if (category.equals(CategoryNames.PC_FILE_TRANSFER)) { | |
Intent exp = new Intent(this, FileServerActivity.class); | |
startActivity(exp); | |
} else { | |
Intent exp = new Intent(this, ExplorerActivity.class); | |
exp.putExtra("category", category); | |
startActivity(exp); | |
} | |
} | |
} | |
private void checkPermissions() { | |
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED | |
|| ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { | |
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, FILE_PERMISSION_CODE); | |
} else { | |
init(); | |
dashboardPresenter.initCategories(); | |
dashboardPresenter.getDataSources(); | |
} | |
} | |
@Override | |
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | |
switch (requestCode) { | |
case FILE_PERMISSION_CODE: { | |
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | |
init(); | |
dashboardPresenter.initCategories(); | |
dashboardPresenter.getDataSources(); | |
} else { | |
Snackbar.make(activityDashboardDrawer, getString(R.string.no_permission_text), Snackbar.LENGTH_SHORT).show(); | |
} | |
break; | |
} | |
} | |
} | |
@Override | |
protected void onStart() { | |
super.onStart(); | |
FirebaseAppIndex.getInstance().update(getIndexable()); | |
IntentFilter intentFilter = new IntentFilter(UsbManager.ACTION_USB_DEVICE_DETACHED); | |
registerReceiver(otgReceiver, intentFilter); | |
} | |
private Indexable getIndexable() { | |
return Indexables.noteDigitalDocumentBuilder() | |
.setName(getString(R.string.app_name)) | |
.setUrl(getString(R.string.app_link) + Locale.getDefault().getLanguage()) | |
.build(); | |
} | |
@Override | |
protected void onStop() { | |
super.onStop(); | |
unregisterReceiver(otgReceiver); | |
} | |
private void init() { | |
addNewCategoryButton.setOnClickListener(this); | |
showMoreLayout.setOnClickListener(this); | |
addCloudButton.setOnClickListener(this); | |
analyseButton.setOnClickListener(this); | |
categoryLayoutHeight = categoryLinearLayout.getHeight(); | |
int itemCount = 2; | |
if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE) | |
itemCount = 3; | |
staggeredGridLayoutManager = new StaggeredGridLayoutManager(itemCount, 1); | |
linearLayoutManager = new LinearLayoutManager(this); | |
categoryRecyclerView.setNestedScrollingEnabled(false); | |
categoryRecyclerView.setHasFixedSize(true); | |
categoryRecyclerView.setItemViewCacheSize(20); | |
categoryRecyclerView.setDrawingCacheEnabled(true); | |
categoryRecyclerView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW); | |
dataSourceRecyclerView.setNestedScrollingEnabled(false); | |
arrowImageView.setColorFilter(ContextCompat.getColor(this, R.color.secondaryDarkText)); | |
} | |
@SuppressWarnings("RestrictedApi") | |
private void clearFocus() { | |
searchView.clearFocus(); | |
categoryRecyclerView.requestFocus(); | |
} | |
@Override | |
protected void onDestroy() { | |
super.onDestroy(); | |
} | |
private void checkIsFrequentUser() { | |
boolean isFrequentUser = getIntent().getBooleanExtra("isFrequentUser", false); | |
if (isFrequentUser) rateApp(); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
getMenuInflater().inflate(R.menu.dashboard_menu, menu); | |
final MenuItem searchItem = menu.findItem(R.id.action_search); | |
if (searchItem != null) { | |
searchView = (SearchView) MenuItemCompat.getActionView(searchItem); | |
searchView.setOnSearchClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
//some operation | |
} | |
}); | |
String theme = Prefs.getString("app_theme", this.getString(R.string.theme_yellow)); | |
EditText searchPlate = searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text); | |
searchPlate.setHint(this.getString(R.string.search)); | |
if (this.getString(R.string.dark_theme).equals(theme)) searchPlate.setHintTextColor(ContextCompat.getColor(this,R.color.gray)); | |
else searchPlate.setHintTextColor(ContextCompat.getColor(this,R.color.white_search)); | |
searchPlate.setTextColor(ContextCompat.getColor(this,R.color.white)); | |
View searchPlateView = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate); | |
searchPlateView.setBackgroundColor(ContextCompat.getColor(this, android.R.color.transparent)); | |
searchView.setOnQueryTextListener(this); | |
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); | |
searchView.setSearchableInfo(searchManager.getSearchableInfo( | |
new ComponentName(this, DashboardActivity.class))); | |
clearFocus(); | |
} | |
return super.onCreateOptionsMenu(menu); | |
} | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
int id = item.getItemId(); | |
switch (id) { | |
case R.id.feedBack: | |
GmFileManagerApplication.getInstance().trackEvent(AnalyticsConstants.SCREEN_EVENT, "OpenFeedback", "Geri bildirim ekranı açılıyor"); | |
Intent intent = new Intent(this, FeedbackActivity.class); | |
intent.putExtra("theme", getApplicationInfo().theme); | |
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(GmFileManagerApplication.getContext()); | |
String theme = pref.getString("app_theme", getString(R.string.theme_yellow)); | |
intent.putExtra("app_theme", theme); | |
intent.putExtra("app_name", "File Manager"); | |
startActivity(intent); | |
return true; | |
case R.id.aboutApp: | |
GmFileManagerApplication.getInstance().trackEvent(AnalyticsConstants.SCREEN_EVENT, "OpenAbout", "Hakkında ekranı açılıyor"); | |
Intent intent1 = new Intent(this, AboutView.class); | |
startActivity(intent1); | |
return true; | |
case R.id.settings: | |
GmFileManagerApplication.getInstance().trackEvent(AnalyticsConstants.SCREEN_EVENT, "OpenSettings", "Ayarlar ekranı açılıyor"); | |
Intent settingsIntent = new Intent(this, SettingsActivity.class); | |
startActivity(settingsIntent); | |
return true; | |
case R.id.share: | |
GmFileManagerApplication.getInstance().trackEvent(AnalyticsConstants.SCREEN_EVENT, "OpenShareApp", "Uygulama paylaşılıyor"); | |
shareWithFriends(); | |
return true; | |
case R.id.imean: | |
if (isNetworkConnected()) | |
startActivity(new Intent(this, iMeanLoginActivity.class)); | |
else | |
Toast.makeText(this, R.string.need_connection, Toast.LENGTH_SHORT).show(); | |
return true; | |
} | |
return super.onOptionsItemSelected(item); | |
} | |
private boolean isNetworkConnected() { | |
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); | |
return cm.getActiveNetworkInfo() != null; | |
} | |
private void shareWithFriends() { | |
Intent shareIntent = new Intent(this, ShareActivity.class); | |
shareIntent.putExtra(ShareActivity.APP_LINK_KEY, getString(R.string.app_link)); | |
shareIntent.putExtra(ShareActivity.DRAWABLE_KEY, R.mipmap.ic_launcher); | |
shareIntent.putExtra(ShareActivity.APP_NAME_KEY, getString(R.string.app_name)); | |
shareIntent.putExtra(ShareActivity.APP_PLAY_IMAGE_KEY, "http://telpacdn2.streamprovider.net/GMLabs/AppIcons/ic_file_manager.png"); | |
shareIntent.putExtra(ShareActivity.FACEBOOK_APP_LINK_KEY, "https://l.facebook.com/l.php?u=https%3A%2F%2Ffb.me%2F1220954171331923&h=zAQE5XrOq"); | |
String shareTheme = PreferenceManager.getDefaultSharedPreferences(this).getString("app_theme", getString(R.string.theme_yellow)); | |
shareIntent.putExtra(ShareActivity.APP_THEME_KEY, shareTheme); | |
startActivity(shareIntent); | |
} | |
@Override | |
public void loadCategories() { | |
categoryAdapter = new CategoryAdapter(DashboardActivity.this); | |
categoryAdapter.setOnClickListener(this); | |
categoryAdapter.setHasStableIds(true); | |
ItemTouchHelper.Callback callback = new CategoryCallBack(categoryAdapter); | |
ItemTouchHelper touchHelper = new ItemTouchHelper(callback); | |
touchHelper.attachToRecyclerView(categoryRecyclerView); | |
categoryRecyclerView.setLayoutManager(staggeredGridLayoutManager); | |
categoryRecyclerView.setAdapter(categoryAdapter); | |
dashboardPresenter.getCategoryCounts(); | |
} | |
@Override | |
public void showMoreCategoryList(List<Category> categoryList) { | |
GmFileManagerApplication.getInstance().trackEvent(AnalyticsConstants.SCREEN_EVENT, "showMoreCategoryList", "tümünü göster butonu"); | |
categoryAdapter.addCategoryRange(categoryList); | |
categoryAdapter.notifyItemRangeInserted(categoryAdapter.getCategoryList().size() - 1, categoryList.size()); | |
} | |
@Override | |
public void showLessCategoryList(List<Category> categoryList) { | |
GmFileManagerApplication.getInstance().trackEvent(AnalyticsConstants.SCREEN_EVENT, "showLessCategoryList", "daha az göster"); | |
for (Category category : categoryList) { | |
categoryAdapter.deleteCategory(category); | |
categoryAdapter.notifyItemRemoved(category.getCategoryOrder()); | |
} | |
} | |
@Override | |
public void hideShowMoreButton() { | |
showMoreLayout.setVisibility(View.GONE); | |
} | |
@Override | |
public void showShowMoreButton() { | |
showMoreLayout.setVisibility(View.VISIBLE); | |
} | |
@Override | |
public void rateApp() { | |
final Context context = this; | |
AlertDialog.Builder builder = new AlertDialog.Builder(context); | |
View view = getLayoutInflater().inflate(R.layout.dialog_rate, null); | |
builder.setView(view); | |
Button btnRatingLater = view.findViewById(R.id.btn_rating_later); | |
Button chkRating = view.findViewById(R.id.chk_rating); | |
RatingBar ratingBar = (RatingBar) view.findViewById(R.id.ratingBar); | |
final AlertDialog dialog = builder.create(); | |
ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() { | |
@Override | |
public void onRatingChanged(RatingBar ratingBar, float v, boolean b) { | |
int rate = (int) ratingBar.getRating(); | |
GmFileManagerApplication.getInstance().trackEvent(AnalyticsConstants.SCREEN_EVENT, "RATING", "Kullanıcının verdiği oy : " + rate); | |
if (rate > 4) { | |
GmFileManagerApplication.getInstance().trackEvent(AnalyticsConstants.SCREEN_EVENT, "RATING", "Kullanıcı play store yönlendirildi"); | |
dashboardPresenter.userRated(true, rate); | |
dialog.dismiss(); | |
Uri uri = Uri.parse("market://details?id=" + context.getPackageName()); | |
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); | |
goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | | |
Intent.FLAG_ACTIVITY_NEW_DOCUMENT | | |
Intent.FLAG_ACTIVITY_MULTIPLE_TASK); | |
try { | |
context.startActivity(goToMarket); | |
} catch (ActivityNotFoundException e) { | |
context.startActivity(new Intent(Intent.ACTION_VIEW, | |
Uri.parse("http://play.google.com/store/apps/details?id=" + context.getPackageName()))); | |
} | |
} else { | |
dashboardPresenter.userRated(false, rate); | |
dialog.dismiss(); | |
Toast.makeText(getApplicationContext(), getString(R.string.rated_bad), Toast.LENGTH_SHORT).show(); | |
//startActivity(new Intent(DashboardActivity.this,FeedbackActivity.class)); | |
} | |
} | |
}); | |
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { | |
@Override | |
public void onDismiss(DialogInterface dialog) { | |
dashboardPresenter.userRated(false, 0); | |
} | |
}); | |
btnRatingLater.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
dialog.dismiss(); | |
} | |
}); | |
chkRating.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
dashboardPresenter.userRated(false, 0); | |
dialog.dismiss(); | |
// Toast.makeText(getApplicationContext(), getString(R.string.rated_bad), Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); | |
dialog.show(); | |
} | |
@Override | |
public void requestSdCardPermission() { | |
} | |
@Override | |
public void showCategoryList(List<Category> categoryList) { | |
categoryAdapter.setCategoryList(categoryList); | |
categoryAdapter.notifyDataSetChanged(); | |
} | |
@Override | |
public void showDataSourceList(List<DataSourceInfo> dataSourceInfoList) { | |
dataSourceAdapter = new DataSourceAdapter(this); | |
String theme = Prefs.getString("app_theme", this.getString(R.string.theme_yellow)); | |
DividerItemDecoration horizontalDecoration = new DividerItemDecoration(dataSourceRecyclerView.getContext(), | |
DividerItemDecoration.VERTICAL); | |
if(this.getString(R.string.dark_theme).equals(theme)){ | |
Drawable horizontalDividerDark = ContextCompat.getDrawable(this, R.drawable.horizontal_divider_dark); | |
horizontalDecoration.setDrawable(horizontalDividerDark); | |
}else{ | |
Drawable horizontalDivider = ContextCompat.getDrawable(this, R.drawable.horizontal_divider); | |
horizontalDecoration.setDrawable(horizontalDivider); | |
} | |
dataSourceRecyclerView.addItemDecoration(horizontalDecoration); | |
dataSourceRecyclerView.setLayoutManager(linearLayoutManager); | |
dataSourceRecyclerView.setAdapter(dataSourceAdapter); | |
dataSourceAdapter.setDataSourceInfoList(dataSourceInfoList); | |
dataSourceAdapter.setOnItemClickListener(this); | |
dataSourceAdapter.notifyDataSetChanged(); | |
} | |
@Override | |
public boolean onQueryTextSubmit(String query) { | |
Toast.makeText(this, '"' + query + '"' + getString(R.string.searching), Toast.LENGTH_SHORT).show(); | |
return false; | |
} | |
@Override | |
protected void onNewIntent(Intent intent) { | |
if (Intent.ACTION_SEARCH.equals(intent.getAction())) { | |
GmFileManagerApplication.getInstance().trackEvent(AnalyticsConstants.SCREEN_EVENT, "VoiceSearch", "ana ekrandan sesli arama yapıldı"); | |
String query = intent.getStringExtra(SearchManager.QUERY); | |
Intent explorerIntent = new Intent(this, ExplorerActivity.class); | |
explorerIntent.putExtra(QUERY_KEY, query); | |
startActivity(explorerIntent); | |
} else if (UPDATE_ACTION.equals(intent.getAction())) { | |
dashboardPresenter.getCategoryCounts(); | |
showMoreTextView.setContentDescription(getString(R.string.show_more)); | |
arrowImageView.setContentDescription(getString(R.string.show_more)); | |
showMoreTextView.setText(getString(R.string.show_more)); | |
arrowImageView.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_keyboard_arrow_down_black_24dp)); | |
} else { | |
dashboardPresenter.getDataSources(); | |
fillLocalStorageRecycler(); | |
} | |
String path = intent.getStringExtra("path"); | |
String category = intent.getStringExtra("category"); | |
startExplorerWithPath(path, category); | |
} | |
@Override | |
public boolean onQueryTextChange(String newText) { | |
return false; | |
} | |
@Override | |
public void onItemClick(int position, View v) { | |
super.onItemClick(position, v); | |
if (v.getId() == R.id.dataSourceLayout) { | |
DataSourceInfo dataSourceInfo = dataSourceAdapter.getItem(position); | |
if (dataSourceInfo.getDataSource() == DataSourceType.OTG) { | |
String path = PreferenceManager.getDefaultSharedPreferences(this).getString(UsbUtils.getUsbDiskId(), ""); | |
if (path.isEmpty()) { | |
guideDialogForLEXAUsb(); | |
} else { | |
GmFileManagerApplication.getInstance().trackEvent(AnalyticsConstants.SCREEN_EVENT, "OpenDatasource", "data source açılıyor : USB DataSource "); | |
Intent intent = new Intent(this, ExplorerActivity.class); | |
intent.putExtra(PATH_KEY, ""); | |
intent.putExtra(TYPE_KEY, DataSourceType.OTG); | |
startActivity(intent); | |
} | |
} else { | |
GmFileManagerApplication.getInstance().trackEvent(AnalyticsConstants.SCREEN_EVENT, "OpenDatasource", "data source açılıyor : " + dataSourceInfo.getDataSourceName()); | |
Intent intent = new Intent(this, ExplorerActivity.class); | |
intent.putExtra(TYPE_KEY, dataSourceInfo.getDataSource()); | |
if (dataSourceInfo.getDataSource() == DataSourceType.LOCAL_DATASOURCE) { | |
intent.putExtra(PATH_KEY, dataSourceInfo.getRootPath()); | |
} else { | |
intent.putExtra(CLOUD_ID, (long) dataSourceInfo.getCloudId()); | |
intent.putExtra(PATH_KEY, ""); | |
} | |
startActivity(intent); | |
} | |
} else if (v.getId() == R.id.categoryItemLayout) { | |
String categoryName = categoryAdapter.getCategoryName(position); | |
GmFileManagerApplication.getInstance().trackEvent(AnalyticsConstants.SCREEN_EVENT, "OpenCategory", "category açılıyor : " + categoryName); | |
Intent intent = new Intent(this, ExplorerActivity.class); | |
intent.putExtra(CATEGORY_KEY, categoryName); | |
startActivity(intent); | |
} | |
} | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
if (requestCode == 1903 && resultCode == Activity.RESULT_OK) { | |
super.onActivityResult(requestCode, resultCode, data); | |
} | |
} | |
@Override | |
public void onClick(View v) { | |
super.onClick(v); | |
if (v.getId() == R.id.addNewCategoryButton) { | |
GmFileManagerApplication.getInstance().trackEvent(AnalyticsConstants.SCREEN_EVENT, "OpenEditCategory", "kategori düzenleme açılıyor"); | |
Intent intent = new Intent(this, NewCategoryActivity.class); | |
startActivity(intent); | |
} else if (v.getId() == R.id.showMoreLayout) { | |
clickShowMore(); | |
} else if (v.getId() == R.id.addCloud) { | |
GmFileManagerApplication.getInstance().trackEvent(AnalyticsConstants.SCREEN_EVENT, "OpenCloudList", "ana sayfa cloud ekleme butornu basılıyor"); | |
startActivity(new Intent(this, CloudListActivity.class)); | |
} else if (v.getId() == R.id.analyseButton) { | |
GmFileManagerApplication.getInstance().trackEvent(AnalyticsConstants.SCREEN_EVENT, "OpenAnalyse", "incele butonu analiz sayfası açılıyor"); | |
startActivity(new Intent(this, AnalyseActivity.class)); | |
} else if (v.getId() == R.id.sendAnywhere) { | |
Toast.makeText(this, "send anywhere", Toast.LENGTH_SHORT).show(); | |
} | |
} | |
private void clickShowMore() { | |
if (showMoreTextView.getText().equals(getString(R.string.show_more))) { | |
showMoreTextView.setText(R.string.show_less); | |
showMoreTextView.setContentDescription(getString(R.string.show_less)); | |
arrowImageView.setContentDescription(getString(R.string.show_less)); | |
dashboardPresenter.getAllCategories(); | |
arrowImageView.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_keyboard_arrow_up_black_24dp)); | |
} else { | |
showMoreTextView.setText(R.string.show_more); | |
showMoreTextView.setContentDescription(getString(R.string.show_more)); | |
arrowImageView.setContentDescription(getString(R.string.show_more)); | |
dashboardPresenter.getCategoryCounts(); | |
arrowImageView.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_keyboard_arrow_down_black_24dp)); | |
} | |
} | |
@Override | |
protected void onResume() { | |
super.onResume(); | |
Boolean status = Prefs.getBoolean("doesDriveNeedsUpdate", true); | |
if (status.equals(true)) { | |
Prefs.putBoolean("doesDriveNeedsUpdate", false); | |
dashboardPresenter.getDataSources(); | |
} | |
clearFocus(); | |
if (categoryAdapter != null) { | |
categoryAdapter.notifyDataSetChanged(); | |
} | |
refreshTrashCount(); | |
refreshFrequentlyUsedCount(); | |
onFavoritesChanged(); | |
super.createMenu(toolbar, activityDashboardDrawer, this); | |
} | |
@Override | |
public void onDrawerSlide(View drawerView, float slideOffset) { | |
} | |
@Override | |
public void onDrawerOpened(View drawerView) { | |
} | |
@Override | |
public void onDrawerClosed(View drawerView) { | |
clearFocus(); | |
} | |
@Override | |
public void onDrawerStateChanged(int newState) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment