Commit a7dd8e83 authored by Donald's avatar Donald

a lot of clean

parent 5cf93afe
......@@ -128,7 +128,7 @@ public class SelectAlbumBuilder extends BottomSheetDialogFragment {
exploreModePanel = (LinearLayout) contentView.findViewById(R.id.ll_explore_mode_panel);
imgExploreMode = (IconicsImageView) contentView.findViewById(R.id.toggle_hidden_icon);
theme = new ThemeHelper(getContext());
theme = ThemeHelper.getThemeHelper(getContext());
sdCardPath = ContentHelper.getSdcardPath(getContext());
mRecyclerView.setLayoutManager(new GridLayoutManager(getContext(), 1));
......
......@@ -107,10 +107,54 @@ public class PlayerActivity extends ThemedActivity implements SurfaceHolder.Call
private Toolbar toolbar;
private boolean fullscreen = false;
@SuppressWarnings("ResourceAsColor")
private void initUI(){
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(org.horaapps.leafpic.R.layout.activity_player);
FrameLayout root = (FrameLayout) findViewById(org.horaapps.leafpic.R.id.root);
findViewById(R.id.video_frame).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
toggleControlsVisibility();
}
});
root.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
return !(keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_MENU) && mediaController.dispatchKeyEvent(event);
}
});
root.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.md_black_1000));
shutterView = findViewById(org.horaapps.leafpic.R.id.shutter);
videoFrame = (AspectRatioFrameLayout) findViewById(org.horaapps.leafpic.R.id.video_frame);
surfaceView = (SurfaceView) findViewById(org.horaapps.leafpic.R.id.surface_view);
surfaceView.getHolder().addCallback(this);
mediaController = new CustomMediaController(this, this);
mediController_anchor = findViewById(org.horaapps.leafpic.R.id.media_player_anchor);
mediaController.setAnchorView(root);
initUi();
CookieHandler currentHandler = CookieHandler.getDefault();
if (currentHandler != defaultCookieManager)
CookieHandler.setDefault(defaultCookieManager);
audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this);
audioCapabilitiesReceiver.register();
}
private void initUi() {
toolbar = (Toolbar) findViewById(org.horaapps.leafpic.R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.transparent_black));
toolbar.setNavigationIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_arrow_back));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
......@@ -119,24 +163,27 @@ public class PlayerActivity extends ThemedActivity implements SurfaceHolder.Call
}
});
toolbar.setTitle(getIntent().getData().getPath());
//getSupportActionBar().setDisplayShowTitleEnabled(false);
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
// | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
// | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE);
toolbar.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.transparent_black));
toolbar.animate().translationY(-toolbar.getHeight()).setInterpolator(new AccelerateInterpolator())
.setDuration(0).start();
mediController_anchor.setPadding(0,0,0,Measure.getNavBarHeight(PlayerActivity.this));
mediaController.setBackgroundColor(ContextCompat.getColor(getApplicationContext() ,R.color.transparent_black));
mediaController.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.transparent_black));
}
setStatusBarColor();
setNavBarColor();
@SuppressWarnings("ResourceAsColor")
public void updateUiElements() {
setRecentApp(getString(org.horaapps.leafpic.R.string.app_name));
}
......@@ -149,7 +196,7 @@ public class PlayerActivity extends ThemedActivity implements SurfaceHolder.Call
@Override
public void setNavBarColor() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setNavigationBarColor(ContextCompat.getColor(getApplicationContext() ,R.color.transparent_black));
getWindow().setNavigationBarColor(ContextCompat.getColor(getApplicationContext(), R.color.transparent_black));
}
}
......@@ -204,50 +251,7 @@ public class PlayerActivity extends ThemedActivity implements SurfaceHolder.Call
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(org.horaapps.leafpic.R.layout.activity_player);
FrameLayout root = (FrameLayout) findViewById(org.horaapps.leafpic.R.id.root);
findViewById(R.id.video_frame).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
toggleControlsVisibility();
}
});
root.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
return !(keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_MENU) && mediaController.dispatchKeyEvent(event);
}
});
root.setBackgroundColor(ContextCompat.getColor(getApplicationContext(),R.color.md_black_1000));
shutterView = findViewById(org.horaapps.leafpic.R.id.shutter);
videoFrame = (AspectRatioFrameLayout) findViewById(org.horaapps.leafpic.R.id.video_frame);
surfaceView = (SurfaceView) findViewById(org.horaapps.leafpic.R.id.surface_view);
surfaceView.getHolder().addCallback(this);
mediaController = new CustomMediaController(this, this);
mediController_anchor = findViewById(org.horaapps.leafpic.R.id.media_player_anchor);
mediaController.setAnchorView(root);
//mediaController.setPaddingRelative(0,0,0,Measure.getNavBarHeight(PlayerActivity.this));
toolbar = (Toolbar) findViewById(org.horaapps.leafpic.R.id.toolbar);
initUI();
CookieHandler currentHandler = CookieHandler.getDefault();
if (currentHandler != defaultCookieManager)
CookieHandler.setDefault(defaultCookieManager);
audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this);
audioCapabilitiesReceiver.register();
}
@Override
public void onNewIntent(Intent intent) {
......
......@@ -76,11 +76,14 @@ public class SingleMediaActivity extends SharedMediaActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pager);
SP = PreferenceUtil.getInstance(getApplicationContext());
toolbar = (Toolbar) findViewById(R.id.toolbar);
mViewPager = (HackyViewPager) findViewById(R.id.photos_pager);
SP = PreferenceUtil.getInstance(getApplicationContext());
adapter = new MediaPagerAdapter(getSupportFragmentManager(), getAlbum().getMedia());
initUi();
if (savedInstanceState != null)
mViewPager.setLocked(savedInstanceState.getBoolean(ISLOCKED_ARG, false));
try
......@@ -103,23 +106,22 @@ public class SingleMediaActivity extends SharedMediaActivity {
}
getAlbums().addAlbum(0, album);
}
initUI();
setupUI();
} catch (Exception e) { e.printStackTrace(); }
}
private void initUI() {
private void initUi() {
setSupportActionBar(toolbar);
toolbar.bringToFront();
toolbar.setNavigationIcon(getToolbarIcon(CommunityMaterial.Icon.cmd_arrow_left));
toolbar.setNavigationIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_arrow_back));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
setRecentApp(getString(R.string.app_name));
setupSystemUI();
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener
......@@ -130,24 +132,6 @@ public class SingleMediaActivity extends SharedMediaActivity {
else hideSystemUI();
}
});
adapter = new MediaPagerAdapter(getSupportFragmentManager(), getAlbum().getMedia());
adapter.setVideoOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (SP.getBoolean("set_internal_player", false)) {
Intent mpdIntent = new Intent(SingleMediaActivity.this, PlayerActivity.class)
.setData(getAlbum().getCurrentMedia().getUri());
startActivity(mpdIntent);
} else {
Intent intentOpenWith = new Intent(Intent.ACTION_VIEW);
intentOpenWith.setDataAndType(
getAlbum().getMedia().get(mViewPager.getCurrentItem()).getUri(),
getAlbum().getMedia().get(mViewPager.getCurrentItem()).getMimeType());
startActivity(intentOpenWith);
}
}
});
updatePageTitle(getAlbum().getCurrentMediaIndex());
......@@ -179,11 +163,9 @@ public class SingleMediaActivity extends SharedMediaActivity {
configuration.orientation = Configuration.ORIENTATION_LANDSCAPE;
onConfigurationChanged(configuration);
}
}
private void setupUI() {
public void updateUiElements() {
/**** Theme ****/
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setBackgroundColor(
......@@ -198,6 +180,7 @@ public class SingleMediaActivity extends SharedMediaActivity {
setStatusBarColor();
setNavBarColor();
setRecentApp(getString(R.string.app_name));
/**** SETTINGS ****/
......@@ -205,6 +188,7 @@ public class SingleMediaActivity extends SharedMediaActivity {
if (SP.getBoolean("set_max_luminosity", false))
updateBrightness(1.0F);
else try {
// TODO: 12/4/16 redo
float brightness = android.provider.Settings.System.getInt(
getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS);
brightness = brightness == 1.0F ? 255.0F : brightness;
......@@ -216,19 +200,13 @@ public class SingleMediaActivity extends SharedMediaActivity {
if (SP.getBoolean("set_picture_orientation", false))
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
else setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
}
private void updatePageTitle(int position) {
getSupportActionBar().setTitle((position + 1) + " " + getString(R.string.of) + " " + adapter.getCount());
}
@Override
public void onResume() {
super.onResume();
setupUI();
}
@Override
public void onLowMemory() {
super.onLowMemory();
......@@ -280,7 +258,7 @@ public class SingleMediaActivity extends SharedMediaActivity {
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (data != null && resultCode == RESULT_OK) {
switch (requestCode) {
case UCrop.REQUEST_CROP:
......@@ -301,6 +279,7 @@ public class SingleMediaActivity extends SharedMediaActivity {
StringUtils.showToast(getApplicationContext(), "errori random");
break;
default:
super.onActivityResult(requestCode, resultCode, data);
break;
}
}
......
......@@ -16,7 +16,6 @@ import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.Toast;
import org.horaapps.leafpic.LookForMediaJob;
......@@ -47,9 +46,7 @@ public class SplashScreen extends SharedMediaActivity {
final static int ALBUMS_BACKUP = 60;
private boolean PICK_INTENT = false;
public final static String ACTION_OPEN_ALBUM = "com.horaapps.leafpic.OPEN_ALBUM";
//private HandlingAlbums albums;
private Album album;
private Album tmpAlbum;
private PreferenceUtil SP;
......@@ -60,10 +57,6 @@ public class SplashScreen extends SharedMediaActivity {
SP = PreferenceUtil.getInstance(getApplicationContext());
startLookingForMedia();
((ProgressBar) findViewById(R.id.progress_splash)).getIndeterminateDrawable().setColorFilter(getPrimaryColor(), PorterDuff.Mode.SRC_ATOP);
RelativeLayout RelLay = (RelativeLayout) findViewById(org.horaapps.leafpic.R.id.Splah_Bg);
RelLay.setBackgroundColor(getBackgroundColor());
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
......@@ -81,7 +74,7 @@ public class SplashScreen extends SharedMediaActivity {
if (ab != null) {
File dir = new File(ab);
// TODO: 19/08/16 look for id
album = new Album(getApplicationContext(), dir.getAbsolutePath(), data.getInt("albumId", -1), dir.getName(), -1);
tmpAlbum = new Album(getApplicationContext(), dir.getAbsolutePath(), data.getInt("albumId", -1), dir.getName(), -1);
new PrefetchPhotosData().execute();
}
} else StringUtils.showToast(getApplicationContext(), "Album not found");
......@@ -120,12 +113,15 @@ public class SplashScreen extends SharedMediaActivity {
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PICK_MEDIA_REQUEST) {
if (resultCode == RESULT_OK) {
setResult(RESULT_OK, data);
finish();
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case PICK_MEDIA_REQUEST:
if (resultCode == RESULT_OK) {
setResult(RESULT_OK, data);
finish();
}
break;
default: super.onActivityResult(requestCode, resultCode, data);
}
}
......@@ -160,6 +156,12 @@ public class SplashScreen extends SharedMediaActivity {
}
}
@Override
public void updateUiElements() {
((ProgressBar) findViewById(R.id.progress_splash)).getIndeterminateDrawable().setColorFilter(getPrimaryColor(), PorterDuff.Mode.SRC_ATOP);
findViewById(org.horaapps.leafpic.R.id.Splah_Bg).setBackgroundColor(getBackgroundColor());
}
private class PrefetchAlbumsData extends AsyncTask<Boolean, Boolean, Boolean> {
@Override
......@@ -195,7 +197,7 @@ public class SplashScreen extends SharedMediaActivity {
private class PrefetchPhotosData extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... arg0) {
album.updatePhotos(getApplicationContext());
tmpAlbum.updatePhotos(getApplicationContext());
return null;
}
......@@ -204,7 +206,7 @@ public class SplashScreen extends SharedMediaActivity {
super.onPostExecute(result);
Intent i = new Intent(SplashScreen.this, MainActivity.class);
Bundle b = new Bundle();
getAlbums().addAlbum(0, album);
getAlbums().addAlbum(0, tmpAlbum);
b.putInt(CONTENT, PHOTOS_PREFETCHED);
i.putExtras(b);
startActivity(i);
......
......@@ -37,6 +37,7 @@ import org.horaapps.leafpic.model.base.ImageFileFilter;
import org.horaapps.leafpic.util.AlertDialogsHelper;
import org.horaapps.leafpic.util.ContentHelper;
import org.horaapps.leafpic.util.StringUtils;
import org.jetbrains.annotations.TestOnly;
import java.io.File;
import java.util.ArrayList;
......@@ -53,16 +54,24 @@ public class WhiteListActivity extends ThemedActivity {
ArrayList<Item> folders = new ArrayList<>();
ArrayList<String> alreadyTracked;
RecyclerView mRecyclerView;
Toolbar toolbar;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_track_albums);
toolbar = (Toolbar) findViewById(org.horaapps.leafpic.R.id.toolbar);
mRecyclerView = (RecyclerView) findViewById(org.horaapps.leafpic.R.id.excluded_albums);
fabWHDone = (FloatingActionButton) findViewById(R.id.fab_whitelist_done);
initUi();
tracker = HandlingAlbums.getInstance(getApplicationContext());
alreadyTracked = tracker.getTrackedPaths();
lookForFoldersInMediaStore();
initUI();
}
private void lookForFoldersInMediaStore() {
String[] projection = new String[]{
MediaStore.Files.FileColumns.PARENT,
......@@ -99,7 +108,7 @@ public class WhiteListActivity extends ThemedActivity {
}
}
@Deprecated
@TestOnly
private void fetchFolders(File dir) {
// if (!alreadyTracked.contains(dir)) {
// if (isFolderWithMedia(dir))
......@@ -111,7 +120,7 @@ public class WhiteListActivity extends ThemedActivity {
// }
}
@Deprecated
@TestOnly
private boolean isFolderWithMedia(File dir) {
String[] list = dir.list(new ImageFileFilter(true));
return list != null && list.length > 0;
......@@ -141,28 +150,23 @@ public class WhiteListActivity extends ThemedActivity {
return super.onOptionsItemSelected(item);
}
private void initUI(){
RecyclerView mRecyclerView;
Toolbar toolbar;
private void initUi() {
/** TOOLBAR **/
toolbar = (Toolbar) findViewById(org.horaapps.leafpic.R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
toolbar.setNavigationIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_arrow_back));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
/** RECYCLE VIEW**/
mRecyclerView = (RecyclerView) findViewById(org.horaapps.leafpic.R.id.excluded_albums);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setAdapter(new ItemsAdapter());
mRecyclerView.setLayoutManager(new GridLayoutManager(this, 1));
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mRecyclerView.setBackgroundColor(getBackgroundColor());
/** FAB **/
fabWHDone = (FloatingActionButton) findViewById(R.id.fab_whitelist_done);
fabWHDone.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
fabWHDone.setImageDrawable(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_done).color(Color.WHITE));
fabWHDone.setVisibility(View.VISIBLE);
fabWHDone.setOnClickListener(new View.OnClickListener() {
......@@ -172,20 +176,16 @@ public class WhiteListActivity extends ThemedActivity {
finish();
}
});
}
/**SET UP UI COLORS**/
@Override
public void updateUiElements(){
toolbar.setBackgroundColor(getPrimaryColor());
toolbar.setNavigationIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_arrow_back));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
mRecyclerView.setBackgroundColor(getBackgroundColor());
fabWHDone.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
setStatusBarColor();
setNavBarColor();
setRecentApp(getString(R.string.chose_folders));
findViewById(org.horaapps.leafpic.R.id.rl_ea).setBackgroundColor(getBackgroundColor());
}
......@@ -243,8 +243,9 @@ public class WhiteListActivity extends ThemedActivity {
this.id = id;
}
void toggleInclude() {
boolean toggleInclude() {
included = !included;
return included;
}
}
......@@ -254,8 +255,9 @@ public class WhiteListActivity extends ThemedActivity {
@Override
public void onClick(View v) {
int pos = (int) v.findViewById(R.id.folder_path).getTag();
folders.get(pos).toggleInclude();
notifyItemChanged(pos);
SwitchCompat s = (SwitchCompat) v.findViewById(R.id.tracked_status);
s.setChecked(folders.get(pos).toggleInclude());
//notifyItemChanged(pos);
}
};
......@@ -269,17 +271,17 @@ public class WhiteListActivity extends ThemedActivity {
public void onBindViewHolder(final ItemsAdapter.ViewHolder holder, final int position) {
Item itm = folders.get(position);
holder.album_path.setText(itm.path);
holder.album_name.setText(itm.name);
holder.album_path.setTag(position);
holder.imgUnExclude.setChecked(itm.included);
holder.path.setText(itm.path);
holder.name.setText(itm.name);
holder.path.setTag(position);
holder.tracked.setChecked(itm.included);
/**SET LAYOUT THEME**/
holder.album_name.setTextColor(getTextColor());
holder.album_path.setTextColor(getSubTextColor());
holder.name.setTextColor(getTextColor());
holder.path.setTextColor(getSubTextColor());
holder.imgFolder.setColor(getIconColor());
updateSwitchColor(holder.imgUnExclude, getAccentColor());
holder.card_layout.setBackgroundColor(getCardBackgroundColor());
setSwitchColor(holder.tracked, getAccentColor());
holder.layout.setBackgroundColor(getCardBackgroundColor());
}
public int getItemCount() {
......@@ -287,19 +289,19 @@ public class WhiteListActivity extends ThemedActivity {
}
class ViewHolder extends RecyclerView.ViewHolder {
LinearLayout card_layout;
SwitchCompat imgUnExclude;
LinearLayout layout;
SwitchCompat tracked;
IconicsImageView imgFolder;
TextView album_name;
TextView album_path;
TextView name;
TextView path;
ViewHolder(View itemView) {
super(itemView);
card_layout = (LinearLayout) itemView.findViewById(R.id.linear_card_excluded);
imgUnExclude = (SwitchCompat) itemView.findViewById(R.id.tracked_status);
layout = (LinearLayout) itemView.findViewById(R.id.linear_card_excluded);
tracked = (SwitchCompat) itemView.findViewById(R.id.tracked_status);
imgFolder = (IconicsImageView) itemView.findViewById(R.id.folder_icon);
album_name = (TextView) itemView.findViewById(R.id.folder_name);
album_path = (TextView) itemView.findViewById(R.id.folder_path);
name = (TextView) itemView.findViewById(R.id.folder_name);
path = (TextView) itemView.findViewById(R.id.folder_path);
}
}
}
......
package org.horaapps.leafpic.activities.base;
import android.os.Bundle;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AlertDialog;
import android.widget.Toast;
import org.horaapps.leafpic.MyApplication;
import org.horaapps.leafpic.R;
import org.horaapps.leafpic.model.Album;
import org.horaapps.leafpic.model.HandlingAlbums;
import org.horaapps.leafpic.util.AlertDialogsHelper;
import org.horaapps.leafpic.util.ContentHelper;
/**
* Created by dnld on 03/08/16.
*/
public class SharedMediaActivity extends ThemedActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public abstract class SharedMediaActivity extends ThemedActivity {
public HandlingAlbums getAlbums() {
return ((MyApplication) getApplicationContext()).getAlbums();
}
private int REQUEST_CODE_SD_CARD_PERMISSIONS = 42;
public Album getAlbum() {
return ((MyApplication) getApplicationContext()).getAlbum();
}
public HandlingAlbums getAlbums() {
return ((MyApplication) getApplicationContext()).getAlbums();
}
public Album getAlbum() {
return ((MyApplication) getApplicationContext()).getAlbum();
}
public void requestSdCardPermissions() {
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this, getDialogStyle());
AlertDialogsHelper.getTextDialog(this, dialogBuilder,
R.string.sd_card_write_permission_title, R.string.sd_card_permissions_message);
dialogBuilder.setPositiveButton(getString(R.string.ok_action).toUpperCase(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP)
startActivityForResult(new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE), REQUEST_CODE_SD_CARD_PERMISSIONS);
}
});
dialogBuilder.show();
}
@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent resultData) {
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_CODE_SD_CARD_PERMISSIONS) {
Uri treeUri = resultData.getData();
// Persist URI in shared preference so that you can use it later.
ContentHelper.saveSdCardInfo(getApplicationContext(), treeUri);
getContentResolver().takePersistableUriPermission(treeUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
Toast.makeText(this, R.string.got_permission_wr_sdcard, Toast.LENGTH_SHORT).show();
}
}
}
}
package org.horaapps.leafpic.activities.base;
/**
* Created by dnld on 12/4/16.
*/
public interface UiElementInizializer {
void updateUiElements();
}
......@@ -22,6 +22,7 @@ import org.horaapps.leafpic.util.CardViewStyle;
import org.horaapps.leafpic.util.ColorPalette;
import org.horaapps.leafpic.util.PreferenceUtil;
import org.horaapps.leafpic.util.Strin