Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the Bottom Nav Sliding Direction Issue #2924

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/java/org/fossasia/phimpme/MyApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class MyApplication extends Application {
private HandlingAlbums albums = null;
public static Context applicationContext;
private RefWatcher refWatcher;
public int NavItem = 1;

public Album getAlbum() {
return albums.dispAlbums.size() > 0 ? albums.getCurrentAlbum() : Album.getEmptyAlbum();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.twitter.sdk.android.core.identity.TwitterAuthClient;
import io.realm.RealmQuery;
import java.util.ArrayList;
import org.fossasia.phimpme.MyApplication;
import org.fossasia.phimpme.R;
import org.fossasia.phimpme.base.PhimpmeProgressBarHandler;
import org.fossasia.phimpme.base.RecyclerItemClickListner;
Expand Down Expand Up @@ -92,7 +93,7 @@ public void onCreate(Bundle savedInstanceState) {
ActivitySwitchHelper.setContext(this);
setSupportActionBar(toolbar);
parentLayout.setBackgroundColor(getBackgroundColor());
overridePendingTransition(R.anim.right_to_left, R.anim.left_to_right);
startSlideAnimation(2);
phimpmeProgressBarHandler = new PhimpmeProgressBarHandler(this);
ThemeHelper themeHelper = new ThemeHelper(this);
toolbar.setPopupTheme(getPopupToolbarStyle());
Expand All @@ -110,6 +111,16 @@ public void onCreate(Bundle savedInstanceState) {
initObserver();
}

private void startSlideAnimation(int currentMenuItem) {

if (((MyApplication) this.getApplication()).NavItem > currentMenuItem)
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
else if (((MyApplication) this.getApplication()).NavItem < currentMenuItem)
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
// Update the Global NavItem
((MyApplication) this.getApplication()).NavItem = currentMenuItem;
}

private void initObserver() {
accountViewModel.error.observe(
this,
Expand Down Expand Up @@ -348,7 +359,6 @@ public void onBackPressed() {
Intent intent = new Intent(this, LFMainActivity.class);
startActivity(intent);
finish();
overridePendingTransition(R.anim.left_to_right, R.anim.right_to_left);
}

private void boxAuthentication() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public void onPause() {

@Override
public boolean onNavigationItemSelected(@NonNull final MenuItem item) {

if (item.getItemId() != getNavigationMenuItemId()) {
switch (item.getItemId()) {
case R.id.navigation_camera:
Expand All @@ -148,8 +149,8 @@ public boolean onNavigationItemSelected(@NonNull final MenuItem item) {
startActivity(accountIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
break;
}

finish();
overridePendingTransition(R.anim.left_to_right, R.anim.right_to_left);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,35 @@
import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;

/** Created by saurav on 21/6/18. */
/** Created by saurav on 21/6/18. Last Modified by SatyaJiit */

/* Used ID as PrimaryKey instead of filePath
* Since there might be cases that user deletes a file
* which has same name then that would cause a Duplicate PrimaryKey Exception
*/

public class TrashBinRealmModel extends RealmObject {

@PrimaryKey private String trashbinpath;
@PrimaryKey private int id;
private String trashbinpath;
private String oldpath;
private String datetime;
private String timeperiod;

public TrashBinRealmModel() {}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public void setTrashbinpath(String trashbinpath) {
this.trashbinpath = trashbinpath;
}

public String getTrashbinpath() {
return trashbinpath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
import java.util.Locale;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.fossasia.phimpme.MyApplication;
import org.fossasia.phimpme.R;
import org.fossasia.phimpme.base.SharedMediaActivity;
import org.fossasia.phimpme.data.local.FavouriteImagesModel;
Expand Down Expand Up @@ -660,8 +661,7 @@ public void onCreate(Bundle savedInstanceState) {

rvAlbums = findViewById(R.id.grid_albums);
rvMedia = findViewById(R.id.grid_photos);

overridePendingTransition(R.anim.right_to_left, R.anim.left_to_right);
startSlideAnimation(1);
SP = PreferenceUtil.getInstance(getApplicationContext());
albumsMode = true;
editMode = false;
Expand Down Expand Up @@ -730,6 +730,16 @@ public void onResume() {
firstLaunch = false;
}

private void startSlideAnimation(int currentMenuItem) {

if (((MyApplication) this.getApplication()).NavItem > currentMenuItem)
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
else if (((MyApplication) this.getApplication()).NavItem < currentMenuItem)
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
// Update the Global NavItem
((MyApplication) this.getApplication()).NavItem = currentMenuItem;
}

private void displayCurrentAlbumMedia(boolean reload) {
toolbar.setTitle(getAlbum().getName());
toolbar.setNavigationIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_arrow_back));
Expand Down Expand Up @@ -3541,13 +3551,33 @@ private void addTrashObjectsToRealm(ArrayList<Media> media) {
int index = media.get(i).getPath().lastIndexOf("/");
String name = media.get(i).getPath().substring(index + 1);
realm.beginTransaction();
Number currentIdNum = realm.where(TrashBinRealmModel.class).max("id");
int nextId;
if (currentIdNum == null) {
nextId = 1;
} else {
nextId = currentIdNum.intValue() + 1;
}

String trashpath = trashbinpath + "/" + name;
TrashBinRealmModel trashBinRealmModel =
realm.createObject(TrashBinRealmModel.class, trashpath);

/* Used ID as PrimaryKey instead of filePath
* Since there might be cases that user deletes a file
* which has same name then that would cause a Duplicate PrimaryKey Exception
*/

TrashBinRealmModel trashBinRealmModel = realm.createObject(TrashBinRealmModel.class, nextId);

// Sets the File Bin Path here
trashBinRealmModel.setTrashbinpath(trashpath);

trashBinRealmModel.setOldpath(media.get(i).getPath());

trashBinRealmModel.setDatetime(
new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new Date()));

trashBinRealmModel.setTimeperiod("null");

realm.commitTransaction();
}
}
Expand Down Expand Up @@ -3661,7 +3691,6 @@ public Bitmap getBitmap(String path) {
}
in.close();

Log.d(TAG, "bitmap size - width: " + bitmap.getWidth() + ", height: " + bitmap.getHeight());
return bitmap;
} catch (IOException e) {
Log.e(TAG, e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ public void onScanCompleted(String s, Uri uri) {
Log.d("scanFile", "onScanCompleted: " + s);
}
});
media.remove(albummedia.get(i));
// This was Causing a change in the length of albummedia
// media.remove(albummedia.get(i));
n++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.fossasia.phimpme.MyApplication;
import org.fossasia.phimpme.R;
import org.fossasia.phimpme.base.ThemedActivity;
import org.fossasia.phimpme.gallery.activities.LFMainActivity;
Expand Down Expand Up @@ -180,7 +181,8 @@ public void onCreate(Bundle savedInstanceState) {
}
super.onCreate(savedInstanceState);
ButterKnife.bind(this);
overridePendingTransition(R.anim.right_to_left, R.anim.left_to_right);

startSlideAnimation(0);
ButterKnife.bind(this);
PreferenceManager.setDefaultValues(
this, R.xml.preferences, false); // initialise any unset preferences to their default values
Expand Down Expand Up @@ -514,6 +516,16 @@ public void run() {
decreaseZoom.setOnClickListener(this);
}

private void startSlideAnimation(int currentMenuItem) {

if (((MyApplication) this.getApplication()).NavItem > currentMenuItem)
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
else if (((MyApplication) this.getApplication()).NavItem < currentMenuItem)
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
// Update the Global NavItem
((MyApplication) this.getApplication()).NavItem = currentMenuItem;
}

/* This method sets the preference defaults which are set specific for a particular device.
* This method should be called when Open Camera is run for the very first time after installation,
* or when the user has requested to "Reset settings".
Expand Down Expand Up @@ -1404,7 +1416,6 @@ public void onBackPressed() {
Intent intent = new Intent(this, LFMainActivity.class);
startActivity(intent);
finish();
overridePendingTransition(R.anim.left_to_right, R.anim.right_to_left);
}

public boolean usingKitKatImmersiveMode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ private void trashEmptyViewSetup() {
private ArrayList<TrashBinRealmModel> getTrashObjects() {
ArrayList<TrashBinRealmModel> list = new ArrayList<>();
final ArrayList<TrashBinRealmModel> toDelete = new ArrayList<>();

for (int i = 0; i < trashBinRealmModelRealmQuery.count(); i++) {

if (new File(trashBinRealmModelRealmQuery.findAll().get(i).getTrashbinpath()).exists()) {
list.add(trashBinRealmModelRealmQuery.findAll().get(i));

Expand All @@ -161,14 +163,15 @@ private ArrayList<TrashBinRealmModel> getTrashObjects() {
}
}
for (int i = 0; i < toDelete.size(); i++) {
final String path = toDelete.get(i).getTrashbinpath();
final int id = toDelete.get(i).getId();
Realm realm = Realm.getDefaultInstance();
realm.executeTransaction(
new Realm.Transaction() {
@Override
public void execute(Realm realm) {
RealmResults<TrashBinRealmModel> realmResults =
realm.where(TrashBinRealmModel.class).equalTo("trashbinpath", path).findAll();
realm.where(TrashBinRealmModel.class).equalTo("id", id).findAll();
// Deleting using the id since its the new PrimaryKey
realmResults.deleteAllFromRealm();
}
});
Expand Down Expand Up @@ -297,8 +300,15 @@ public void execute(Realm realm) {
}
});
File binfolder = new File(Environment.getExternalStorageDirectory() + "/" + ".nomedia");

if (binfolder.exists()) {
binfolder.delete();

// Since bin is not empty we will perform recursive delete on the folder

String[] children = binfolder.list();
for (int i = 0; i < children.length; i++) {
new File(binfolder, children[i]).delete();
}
}
return null;
}
Expand Down
8 changes: 0 additions & 8 deletions app/src/main/res/anim/left_to_right.xml

This file was deleted.

8 changes: 0 additions & 8 deletions app/src/main/res/anim/right_to_left.xml

This file was deleted.

8 changes: 8 additions & 0 deletions app/src/main/res/anim/slide_in_left.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="200"
android:fromXDelta="-100%p"
android:toXDelta="0" />
</set>
8 changes: 8 additions & 0 deletions app/src/main/res/anim/slide_in_right.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="200"
android:fromXDelta="100%p"
android:toXDelta="0" />
</set>
8 changes: 8 additions & 0 deletions app/src/main/res/anim/slide_out_left.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="200"
android:fromXDelta="0"
android:toXDelta="-100%p" />
</set>
8 changes: 8 additions & 0 deletions app/src/main/res/anim/slide_out_right.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="200"
android:fromXDelta="0"
android:toXDelta="100%p" />
</set>