mirror of
https://github.com/UnevenSoftware/LeafPic.git
synced 2026-03-13 08:01:35 +08:00
Added Kotlin support, MultiDex, refactoring.
- Added Kotlin support to the app. Welcome, Kotlin! :) - Added MultiDex support. We finally hit 64K methods! - Refactored BaseFragment. Moved EditModeListener and related interfaces to BaseMediaGridFragment for easier extension of Media Grid fragments. - Removed unnecessary listener setters from MainActivity, we can use onAttach for these. - Fixes crash and behavior #590
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
|
||||
repositories {
|
||||
maven { url "http://dl.bintray.com/dasar/maven" }
|
||||
maven { url "https://s3.amazonaws.com/repo.commonsware.com" }
|
||||
maven { url "https://jitpack.io" }
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +18,8 @@ android {
|
||||
versionName "v0.7-alpha-2"
|
||||
versionCode 16
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
|
||||
multiDexEnabled true
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
@@ -132,6 +136,8 @@ dependencies {
|
||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
|
||||
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'
|
||||
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
implementation 'com.android.support:multidex:1.0.3'
|
||||
|
||||
// TODO check them out
|
||||
implementation 'com.turingtechnologies.materialscrollbar:lib:10.0.3'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.horaapps.leafpic;
|
||||
|
||||
import android.app.Application;
|
||||
import android.support.multidex.MultiDexApplication;
|
||||
|
||||
import com.mikepenz.community_material_typeface_library.CommunityMaterial;
|
||||
import com.mikepenz.fontawesome_typeface_library.FontAwesome;
|
||||
@@ -15,7 +15,7 @@ import org.horaapps.leafpic.util.preferences.Prefs;
|
||||
/**
|
||||
* Created by dnld on 28/04/16.
|
||||
*/
|
||||
public class App extends Application {
|
||||
public class App extends MultiDexApplication {
|
||||
|
||||
private static App mInstance;
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ public class MainActivity extends SharedMediaActivity implements
|
||||
return;
|
||||
}
|
||||
|
||||
/** We have some instance state */
|
||||
/* We have some instance state */
|
||||
restoreState(savedInstanceState);
|
||||
|
||||
switch (fragmentMode) {
|
||||
@@ -126,21 +126,13 @@ public class MainActivity extends SharedMediaActivity implements
|
||||
case FragmentMode.MODE_MEDIA:
|
||||
rvMediaFragment = (RvMediaFragment) getSupportFragmentManager().findFragmentByTag(RvMediaFragment.TAG);
|
||||
rvMediaFragment.setListener(this);
|
||||
rvMediaFragment.setEditModeListener(this);
|
||||
rvMediaFragment.setNothingToShowListener(this);
|
||||
break;
|
||||
|
||||
case FragmentMode.MODE_ALBUMS:
|
||||
albumsFragment = (AlbumsFragment) getSupportFragmentManager().findFragmentByTag(AlbumsFragment.TAG);
|
||||
albumsFragment.setListener(this);
|
||||
albumsFragment.setEditModeListener(this);
|
||||
albumsFragment.setNothingToShowListener(this);
|
||||
break;
|
||||
|
||||
case FragmentMode.MODE_TIMELINE:
|
||||
TimelineFragment timelineFragment = (TimelineFragment) getSupportFragmentManager().findFragmentByTag(TimelineFragment.TAG);
|
||||
timelineFragment.setEditModeListener(this);
|
||||
timelineFragment.setNothingToShowListener(this);
|
||||
setupUiForTimeline();
|
||||
}
|
||||
}
|
||||
@@ -155,9 +147,6 @@ public class MainActivity extends SharedMediaActivity implements
|
||||
|
||||
private void initAlbumsFragment() {
|
||||
albumsFragment = new AlbumsFragment();
|
||||
albumsFragment.setListener(this);
|
||||
albumsFragment.setEditModeListener(this);
|
||||
albumsFragment.setNothingToShowListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -185,8 +174,6 @@ public class MainActivity extends SharedMediaActivity implements
|
||||
lockNavigationDrawer();
|
||||
|
||||
rvMediaFragment.setListener(this);
|
||||
rvMediaFragment.setEditModeListener(this);
|
||||
rvMediaFragment.setNothingToShowListener(this);
|
||||
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
@@ -200,9 +187,6 @@ public class MainActivity extends SharedMediaActivity implements
|
||||
|
||||
fragmentMode = FragmentMode.MODE_TIMELINE;
|
||||
|
||||
fragment.setEditModeListener(this);
|
||||
fragment.setNothingToShowListener(this);
|
||||
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(R.id.content, fragment, TimelineFragment.TAG)
|
||||
|
||||
@@ -60,7 +60,7 @@ import jp.wasabeef.recyclerview.animators.LandingAnimator;
|
||||
* Created by dnld on 3/13/17.
|
||||
*/
|
||||
|
||||
public class AlbumsFragment extends BaseFragment {
|
||||
public class AlbumsFragment extends BaseMediaGridFragment {
|
||||
|
||||
public static final String TAG = "AlbumsFragment";
|
||||
|
||||
@@ -78,10 +78,6 @@ public class AlbumsFragment extends BaseFragment {
|
||||
void onAlbumClick(Album album);
|
||||
}
|
||||
|
||||
public void setListener(AlbumClickListener clickListener) {
|
||||
this.listener = clickListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -92,6 +88,7 @@ public class AlbumsFragment extends BaseFragment {
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
if (context instanceof AlbumClickListener) listener = (AlbumClickListener) context;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,33 +1,22 @@
|
||||
package org.horaapps.leafpic.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.horaapps.leafpic.items.ActionsListener;
|
||||
import org.horaapps.liz.Themed;
|
||||
import org.horaapps.liz.ThemedFragment;
|
||||
|
||||
/**
|
||||
* Created by dnld on 4/3/17.
|
||||
* Base Fragment for abstraction logic.
|
||||
*/
|
||||
public abstract class BaseFragment extends ThemedFragment {
|
||||
|
||||
public abstract class BaseFragment extends ThemedFragment implements IFragment, Themed, ActionsListener {
|
||||
|
||||
private EditModeListener editModeListener;
|
||||
private NothingToShowListener nothingToShowListener;
|
||||
|
||||
public boolean onBackPressed(){
|
||||
if (editMode()){
|
||||
clearSelected();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
|
||||
public EditModeListener getEditModeListener() {
|
||||
return editModeListener;
|
||||
}
|
||||
|
||||
public void setEditModeListener(EditModeListener editModeListener) {
|
||||
this.editModeListener = editModeListener;
|
||||
if (context instanceof NothingToShowListener)
|
||||
nothingToShowListener = (NothingToShowListener) context;
|
||||
}
|
||||
|
||||
public NothingToShowListener getNothingToShowListener() {
|
||||
|
||||
@@ -7,12 +7,11 @@ import android.view.View;
|
||||
|
||||
import org.horaapps.leafpic.data.Media;
|
||||
import org.horaapps.liz.ThemeHelper;
|
||||
import org.horaapps.liz.ThemedFragment;
|
||||
|
||||
/**
|
||||
* A Base Fragment for showing Media.
|
||||
*/
|
||||
public abstract class BaseMediaFragment extends ThemedFragment {
|
||||
public abstract class BaseMediaFragment extends BaseFragment {
|
||||
|
||||
private static final String ARGS_MEDIA = "args_media";
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.horaapps.leafpic.fragments
|
||||
|
||||
import android.content.Context
|
||||
|
||||
import org.horaapps.leafpic.items.ActionsListener
|
||||
|
||||
/**
|
||||
* Base class for fragments showing any kind of Media in a Grid fashion.
|
||||
*
|
||||
* Allows selection, multiple select Context Menus, etc.
|
||||
*/
|
||||
abstract class BaseMediaGridFragment : BaseFragment(), IFragment, ActionsListener {
|
||||
|
||||
var editModeListener: EditModeListener? = null
|
||||
|
||||
override fun onAttach(context: Context?) {
|
||||
super.onAttach(context)
|
||||
if (context is EditModeListener) editModeListener = context
|
||||
}
|
||||
|
||||
fun onBackPressed() = when (editMode()) {
|
||||
true -> clearSelected()
|
||||
false -> false
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ import jp.wasabeef.recyclerview.animators.LandingAnimator;
|
||||
* Created by dnld on 3/13/17.
|
||||
*/
|
||||
|
||||
public class RvMediaFragment extends BaseFragment {
|
||||
public class RvMediaFragment extends BaseMediaGridFragment {
|
||||
|
||||
public static final String TAG = "RvMediaFragment";
|
||||
private static final String BUNDLE_ALBUM = "album";
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.horaapps.leafpic.data.provider.CPHelper;
|
||||
import org.horaapps.leafpic.data.sort.MediaComparators;
|
||||
import org.horaapps.leafpic.data.sort.SortingMode;
|
||||
import org.horaapps.leafpic.data.sort.SortingOrder;
|
||||
import org.horaapps.leafpic.fragments.BaseFragment;
|
||||
import org.horaapps.leafpic.fragments.BaseMediaGridFragment;
|
||||
import org.horaapps.leafpic.interfaces.MediaClickListener;
|
||||
import org.horaapps.leafpic.util.DeviceUtils;
|
||||
import org.horaapps.leafpic.util.preferences.Defaults;
|
||||
@@ -42,7 +42,7 @@ import io.reactivex.schedulers.Schedulers;
|
||||
/**
|
||||
* Fragment which shows the Timeline.
|
||||
*/
|
||||
public class TimelineFragment extends BaseFragment {
|
||||
public class TimelineFragment extends BaseMediaGridFragment {
|
||||
|
||||
public static final String TAG = "TimelineFragment";
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.2.41'
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
maven {
|
||||
@@ -9,7 +11,9 @@ buildscript {
|
||||
google()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.1.2'
|
||||
|
||||
classpath 'com.android.tools.build:gradle:3.1.3'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
||||
Reference in New Issue
Block a user