Fixed rare crash on Pixel devices. Fixed app not working on API < 23. Added some snackbars.

parent af539aee
......@@ -7,6 +7,7 @@ import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
......@@ -36,7 +37,6 @@ public class FolderActivity extends AppCompatActivity {
GridViewAdapterImages gridAdapter;
int columns = 3;
@BindView(R.id.swipelayout) SwipeRefreshLayout swipeLayout;
@BindView(R.id.placeholderNoImages) TextView text;
@BindView(R.id.gridViewFolder) GridView gridView;
@BindView(R.id.toolbar) Toolbar toolbar;
......@@ -164,8 +164,6 @@ public class FolderActivity extends AppCompatActivity {
list_of_files.clear();
list_of_paths.clear();
Log.e("test", "load");
// Images-------------------------------------------------------------------------------
uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
......@@ -294,7 +292,8 @@ public class FolderActivity extends AppCompatActivity {
}
// The only image of the folder was deleted
else if(resultCode == 2) {
text.setText(R.string.no_images);
Snackbar.make(findViewById(R.id.main), getString(R.string.no_images), Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
// Folder emptied
setResult(1);
}
......
......@@ -21,7 +21,6 @@ import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.TextView;
import java.io.File;
import java.util.ArrayList;
......@@ -47,8 +46,6 @@ public class MainActivity extends AppCompatActivity {
GridViewAdapterFolders gridAdapter;
@BindView(R.id.swipelayout) SwipeRefreshLayout swipeLayout;
@BindView(R.id.noMediaText) TextView noMediaText;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -74,6 +71,9 @@ public class MainActivity extends AppCompatActivity {
setFABListener();
loadFolders(columns);
}
}else{
setFABListener();
loadFolders(columns);
}
// Set on swipe refresh listener
......@@ -235,11 +235,14 @@ public class MainActivity extends AppCompatActivity {
if (!list_of_folder_names_i.contains(folder_name)) {
list_of_folder_names_i.add(folder_name);
File imgFile = new File(path_of_image);
// Get number of pictures in folder
int files_in_folder = imgFile.getParentFile().listFiles(new Utils.MediaFileFilter()).length;
// Get number of media in folder
int files_in_folder;
if(imgFile.getParentFile().listFiles(new Utils.MediaFileFilter()) != null) {
files_in_folder = imgFile.getParentFile().listFiles(new Utils.MediaFileFilter()).length;
}else{
files_in_folder = 0;
}
// Add to list
list_of_folders_i.add(new FolderItem(imgFile, folder_name, files_in_folder));
}
......@@ -274,11 +277,14 @@ public class MainActivity extends AppCompatActivity {
if (!list_of_folder_names_v.contains(folder_name)) {
list_of_folder_names_v.add(folder_name);
File imgFile = new File(path_of_video);
// Get number of pictures in folder
int files_in_folder = imgFile.getParentFile().listFiles(new Utils.MediaFileFilter()).length;
// Get number of media in folder
int files_in_folder;
if(imgFile.getParentFile().listFiles(new Utils.MediaFileFilter()) != null) {
files_in_folder = imgFile.getParentFile().listFiles(new Utils.MediaFileFilter()).length;
}else{
files_in_folder = 0;
}
// Add to list
list_of_folders_v.add(new FolderItem(imgFile, folder_name, files_in_folder));
}
......@@ -291,7 +297,8 @@ public class MainActivity extends AppCompatActivity {
}
if(isEmpty){
noMediaText.setVisibility(View.VISIBLE);
Snackbar.make(findViewById(R.id.main), getString(R.string.no_media), Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}else {
// Compare the results of both queries and join them together in a single sorted list
boolean match;
......@@ -334,9 +341,7 @@ public class MainActivity extends AppCompatActivity {
list_of_folder_names.add(list_of_folders_i.get(z).getTitle());
}
}
Collections.sort(list_of_folders, new Utils.SortFoldersByName());
// Find GridView to populate
gridView = findViewById(R.id.gridView);
// Set number of columns
......@@ -348,7 +353,6 @@ public class MainActivity extends AppCompatActivity {
columns);
gridView.setAdapter(gridAdapter);
gridAdapter.notifyDataSetChanged();
// OnClick listener
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
......
......@@ -2,9 +2,9 @@
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main"
tools:context="com.systemallica.gallery.MainActivity">
<android.support.design.widget.AppBarLayout
......
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/swipelayout"
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.systemallica.gallery.MainActivity"
tools:context="com.systemallica.gallery.FolderActivity"
android:id="@+id/swipelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main">
tools:showIn="@layout/activity_folder">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
......@@ -24,24 +25,8 @@
android:gravity="center"
android:numColumns="2"
android:stretchMode="columnWidth"
android:nestedScrollingEnabled="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
android:nestedScrollingEnabled="true"/>
</android.support.v4.widget.NestedScrollView>
<TextView
android:id="@+id/placeholderNoImages"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:textColor="@color/text_white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.v4.widget.SwipeRefreshLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout android:layout_width="match_parent"
android:layout_height="match_parent"
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.systemallica.gallery.MainActivity"
android:id="@+id/swipelayout"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/noMediaText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/no_media"
android:textAlignment="center"
android:gravity="center_vertical"
android:visibility="gone" />
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
......@@ -22,9 +17,11 @@
<GridView
android:id="@+id/gridView"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:drawSelectorOnTop="true"
android:focusable="true"
android:gravity="center"
android:numColumns="2"
android:stretchMode="columnWidth"
......@@ -32,4 +29,5 @@
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
\ No newline at end of file
</android.support.v4.widget.SwipeRefreshLayout>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment