Skip to content

Commit 7a29df8

Browse files
authored
Merge pull request #63 from kaczmarkiewiczp/dev
Small improvements
2 parents 0d63d2e + 4ac95a6 commit 7a29df8

12 files changed

+335
-237
lines changed

.idea/assetWizardSettings.xml

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/ca/pkay/rcloneexplorer/Dialogs/ColorPickerDialog.java

+12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.support.v4.app.DialogFragment;
99
import android.support.v4.app.FragmentActivity;
1010
import android.support.v7.app.AlertDialog;
11+
import android.util.TypedValue;
1112
import android.view.LayoutInflater;
1213
import android.view.View;
1314
import android.widget.LinearLayout;
@@ -75,6 +76,7 @@ private void createLayout(View view) {
7576
if (color == defaultColor) {
7677
(item.findViewById(R.id.checkmark)).setVisibility(View.VISIBLE);
7778
visibleCheckmark = item.findViewById(R.id.checkmark);
79+
selectedColor = defaultColor;
7880
}
7981

8082
item.setOnClickListener(new View.OnClickListener() {
@@ -99,6 +101,16 @@ public void onClick(View v) {
99101
i = 0;
100102
}
101103
}
104+
105+
while (i < 5) { // add dummy items so that layout is even
106+
View item = layoutInflater.inflate(R.layout.color_picker_item, null);
107+
View colorOption = item.findViewById(R.id.color_option);
108+
TypedValue typedValue = new TypedValue();
109+
context.getTheme().resolveAttribute(R.attr.cardColor, typedValue, true);
110+
colorOption.getBackground().setTint(typedValue.data);
111+
rowLayout.addView(item);
112+
i++;
113+
}
102114
dialogLayout.addView(row);
103115
}
104116

app/src/main/java/ca/pkay/rcloneexplorer/Fragments/FileExplorerFragment.java

+3-45
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ public class FileExplorerFragment extends Fragment implements FileExplorerRecy
7272
private static final int EX_FILE_PICKER_UPLOAD_RESULT = 186;
7373
private static final int EX_FILE_PICKER_DOWNLOAD_RESULT = 204;
7474
private static final int STREAMING_INTENT_RESULT = 468;
75-
private final int MAX_STREAMING_SIZE = 500000000;
7675
private String originalToolbarTitle;
7776
private List<FileItem> directoryContent;
7877
private Stack<String> pathStack;
@@ -290,21 +289,7 @@ private void showOpenAsDialog() {
290289
public void onClickText() {
291290
if (recyclerViewAdapter.getNumberOfSelectedItems() == 1) {
292291
FileItem fileItem = recyclerViewAdapter.getSelectedItems().get(0);
293-
if (fileItem.getSize() < MAX_STREAMING_SIZE) {
294-
new DownloadAndOpen(DownloadAndOpen.OPEN_AS_TEXT).execute(fileItem);
295-
} else {
296-
AlertDialog.Builder builder;
297-
if (isDarkTheme) {
298-
builder = new AlertDialog.Builder(context, R.style.DarkDialogTheme);
299-
} else {
300-
builder = new AlertDialog.Builder(context);
301-
}
302-
builder
303-
.setMessage(R.string.max_streaming_size_exceeded)
304-
.setNeutralButton(R.string.okay_confirmation, null)
305-
.create()
306-
.show();
307-
}
292+
new DownloadAndOpen(DownloadAndOpen.OPEN_AS_TEXT).execute(fileItem);
308293
}
309294
}
310295
@Override
@@ -322,22 +307,7 @@ public void onClickVideo() {
322307
@Override
323308
public void onClickImage() {
324309
FileItem fileItem = recyclerViewAdapter.getSelectedItems().get(0);
325-
if (fileItem.getSize() < MAX_STREAMING_SIZE) {
326-
new DownloadAndOpen(DownloadAndOpen.OPEN_AS_IMAGE).execute(fileItem);
327-
} else {
328-
AlertDialog.Builder builder;
329-
if (isDarkTheme) {
330-
builder = new AlertDialog.Builder(context, R.style.DarkDialogTheme);
331-
} else {
332-
builder = new AlertDialog.Builder(context);
333-
}
334-
builder
335-
.setMessage(R.string.max_streaming_size_exceeded)
336-
.setNeutralButton(R.string.okay_confirmation, null)
337-
.create()
338-
.show();
339-
}
340-
310+
new DownloadAndOpen(DownloadAndOpen.OPEN_AS_IMAGE).execute(fileItem);
341311
}
342312
});
343313
if (getFragmentManager() != null) {
@@ -594,21 +564,9 @@ public void onFileClicked(FileItem fileItem) {
594564
if (type != null && (type.startsWith("video/") || type.startsWith("audio/"))) {
595565
// stream video or audio
596566
new StreamTask().execute(fileItem);
597-
} else if (fileItem.getSize() < MAX_STREAMING_SIZE){
567+
} else {
598568
// download and open
599569
new DownloadAndOpen().execute(fileItem);
600-
} else {
601-
AlertDialog.Builder builder;
602-
if (isDarkTheme) {
603-
builder = new AlertDialog.Builder(context, R.style.DarkDialogTheme);
604-
} else {
605-
builder = new AlertDialog.Builder(context);
606-
}
607-
builder
608-
.setMessage(R.string.max_streaming_size_exceeded)
609-
.setNeutralButton(R.string.okay_confirmation, null)
610-
.create()
611-
.show();
612570
}
613571
}
614572

app/src/main/java/ca/pkay/rcloneexplorer/SettingsActivity.java

+51-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
package ca.pkay.rcloneexplorer;
22

33
import android.app.ActivityManager;
4+
import android.content.Intent;
45
import android.content.SharedPreferences;
56
import android.graphics.Bitmap;
67
import android.graphics.BitmapFactory;
78
import android.os.Bundle;
89
import android.preference.PreferenceManager;
10+
import android.support.design.widget.Snackbar;
911
import android.support.v7.app.ActionBar;
1012
import android.support.v7.app.AppCompatActivity;
1113
import android.support.v7.widget.Toolbar;
1214
import android.view.View;
1315
import android.widget.CompoundButton;
1416
import android.widget.Switch;
15-
import android.widget.Toast;
17+
import android.widget.TextView;
1618

1719
import ca.pkay.rcloneexplorer.Dialogs.ColorPickerDialog;
18-
import es.dmoral.toasty.Toasty;
1920

2021
public class SettingsActivity extends AppCompatActivity {
2122

@@ -25,6 +26,7 @@ public class SettingsActivity extends AppCompatActivity {
2526
private View accentColorPreview;
2627
private Switch darkThemeSwitch;
2728
private View darkThemeElement;
29+
private View notificationsElement;
2830
private Switch useLogsSwitch;
2931
private View useLogsElement;
3032
private boolean isDarkTheme;
@@ -79,6 +81,7 @@ private void getViews() {
7981
accentColorPreview = findViewById(R.id.accent_color_preview);
8082
darkThemeSwitch = findViewById(R.id.dark_theme_switch);
8183
darkThemeElement = findViewById(R.id.dark_theme);
84+
notificationsElement = findViewById(R.id.notifications);
8285
useLogsSwitch = findViewById(R.id.use_logs_switch);
8386
useLogsElement = findViewById(R.id.use_logs);
8487
}
@@ -131,6 +134,12 @@ public void onClick(View v) {
131134
}
132135
}
133136
});
137+
notificationsElement.setOnClickListener(new View.OnClickListener() {
138+
@Override
139+
public void onClick(View v) {
140+
onNotificationsClicked();
141+
}
142+
});
134143
useLogsSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
135144
@Override
136145
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@@ -186,7 +195,7 @@ private void onPrimaryColorSelected(int color) {
186195
editor.apply();
187196

188197
primaryColorPreview.getBackground().setTint(color);
189-
Toasty.info(this, getString(R.string.restart_required), Toast.LENGTH_SHORT, true).show();
198+
showSnackBar();
190199
}
191200

192201
private void onAccentColorSelected(int color) {
@@ -196,7 +205,7 @@ private void onAccentColorSelected(int color) {
196205
editor.apply();
197206

198207
accentColorPreview.getBackground().setTint(color);
199-
Toasty.info(this, getString(R.string.restart_required), Toast.LENGTH_SHORT, true).show();
208+
showSnackBar();
200209
}
201210

202211
private void onDarkThemeClicked(boolean isChecked) {
@@ -205,7 +214,21 @@ private void onDarkThemeClicked(boolean isChecked) {
205214
editor.putBoolean(getString(R.string.pref_key_dark_theme), isChecked);
206215
editor.apply();
207216

208-
Toasty.info(this, getString(R.string.restart_required), Toast.LENGTH_SHORT, true).show();
217+
showSnackBar();
218+
}
219+
220+
private void onNotificationsClicked() {
221+
Intent intent = new Intent();
222+
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
223+
224+
//for Android 5-7
225+
intent.putExtra("app_package", getPackageName());
226+
intent.putExtra("app_uid", getApplicationInfo().uid);
227+
228+
// for Android O
229+
intent.putExtra("android.provider.extra.APP_PACKAGE", getPackageName());
230+
231+
startActivity(intent);
209232
}
210233

211234
private void onUseLogsClicked(boolean isChecked) {
@@ -214,4 +237,27 @@ private void onUseLogsClicked(boolean isChecked) {
214237
editor.putBoolean(getString(R.string.pref_key_logs), isChecked);
215238
editor.apply();
216239
}
240+
241+
private void showSnackBar() {
242+
Snackbar snackbar = Snackbar.make(findViewById(R.id.cl_activity_settings), R.string.restart_required, Snackbar.LENGTH_LONG);
243+
if (isDarkTheme) {
244+
snackbar.getView().setBackgroundColor(getResources().getColor(R.color.white));
245+
TextView tv = snackbar.getView().findViewById(android.support.design.R.id.snackbar_text);
246+
tv.setTextColor(getResources().getColor(android.R.color.black));
247+
}
248+
snackbar.setAction("Restart", new View.OnClickListener() {
249+
@Override
250+
public void onClick(View v) {
251+
restartApp();
252+
}
253+
});
254+
snackbar.show();
255+
}
256+
257+
private void restartApp() {
258+
Intent intent = new Intent(this, MainActivity.class);
259+
startActivity(intent);
260+
finish();
261+
Runtime.getRuntime().exit(0);
262+
}
217263
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24">
6+
<path
7+
android:fillColor="#FF000000"
8+
android:pathData="M17.75,4.09L15.22,6.03L16.13,9.09L13.5,7.28L10.87,9.09L11.78,6.03L9.25,4.09L12.44,4L13.5,1L14.56,4L17.75,4.09M21.25,11L19.61,12.25L20.2,14.23L18.5,13.06L16.8,14.23L17.39,12.25L15.75,11L17.81,10.95L18.5,9L19.19,10.95L21.25,11M18.97,15.95C19.8,15.87 20.69,17.05 20.16,17.8C19.84,18.25 19.5,18.67 19.08,19.07C15.17,23 8.84,23 4.94,19.07C1.03,15.17 1.03,8.83 4.94,4.93C5.34,4.53 5.76,4.17 6.21,3.85C6.96,3.32 8.14,4.21 8.06,5.04C7.79,7.9 8.75,10.87 10.95,13.06C13.14,15.26 16.1,16.22 18.97,15.95M17.33,17.97C14.5,17.81 11.7,16.64 9.53,14.5C7.36,12.31 6.2,9.5 6.04,6.68C3.23,9.82 3.34,14.64 6.35,17.66C9.37,20.67 14.19,20.78 17.33,17.97Z"/>
9+
</vector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="24.0">
6+
<path
7+
android:fillColor="#FF000000"
8+
android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.89,2 2,2zM18,16v-5c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2z"/>
9+
</vector>

app/src/main/res/layout/activity_settings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
xmlns:tools="http://schemas.android.com/tools"
5+
android:id="@+id/cl_activity_settings"
56
android:layout_width="match_parent"
67
android:layout_height="match_parent"
78
android:background="?attr/backgroundColor"

app/src/main/res/layout/color_picker_item.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
android:layout_width="wrap_content"
55
android:layout_height="wrap_content"
6-
android:paddingStart="12dp"
7-
android:paddingEnd="12dp"
6+
android:paddingStart="8dp"
7+
android:paddingEnd="8dp"
88
android:paddingTop="12dp">
99
<View
1010
android:id="@+id/color_option"

app/src/main/res/layout/color_picker_row.xml

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
android:id="@+id/color_picker_row"
55
android:layout_width="wrap_content"
66
android:layout_height="wrap_content"
7+
android:gravity="center_horizontal"
78
android:orientation="horizontal">
89
</LinearLayout>

0 commit comments

Comments
 (0)