diff --git a/FishBun/src/main/java/com/sangcomz/fishbun/BaseProperty.java b/FishBun/src/main/java/com/sangcomz/fishbun/BaseProperty.java deleted file mode 100644 index b97f4ed2..00000000 --- a/FishBun/src/main/java/com/sangcomz/fishbun/BaseProperty.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.sangcomz.fishbun; - -import android.net.Uri; - -import java.util.ArrayList; - -/** - * Created by sangcomz on 13/05/2017. - */ - -interface BaseProperty { - FishBunCreator setSelectedImages(ArrayList arrayPaths); - - FishBunCreator setPickerCount(int count); - - FishBunCreator setMaxCount(int count); - - FishBunCreator setMinCount(int count); - - FishBunCreator setRequestCode(int RequestCode); - - FishBunCreator setReachLimitAutomaticClose(boolean isAutomaticClose); - - FishBunCreator exceptGif(boolean isExcept); - - void startAlbum(); -} diff --git a/FishBun/src/main/java/com/sangcomz/fishbun/BaseProperty.kt b/FishBun/src/main/java/com/sangcomz/fishbun/BaseProperty.kt new file mode 100644 index 00000000..b3d700e0 --- /dev/null +++ b/FishBun/src/main/java/com/sangcomz/fishbun/BaseProperty.kt @@ -0,0 +1,24 @@ +package com.sangcomz.fishbun + +import android.net.Uri + +/** + * Created by sangcomz on 13/05/2017. + */ +interface BaseProperty { + fun setSelectedImages(selectedImages: ArrayList): FishBunCreator + + fun setPickerCount(count: Int): FishBunCreator + + fun setMaxCount(count: Int): FishBunCreator + + fun setMinCount(count: Int): FishBunCreator + + fun setRequestCode(requestCode: Int): FishBunCreator + + fun setReachLimitAutomaticClose(isAutomaticClose: Boolean): FishBunCreator + + fun exceptGif(isExcept: Boolean): FishBunCreator + + fun startAlbum() +} \ No newline at end of file diff --git a/FishBun/src/main/java/com/sangcomz/fishbun/CustomizationProperty.java b/FishBun/src/main/java/com/sangcomz/fishbun/CustomizationProperty.java deleted file mode 100644 index 7cb47408..00000000 --- a/FishBun/src/main/java/com/sangcomz/fishbun/CustomizationProperty.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.sangcomz.fishbun; - -import android.graphics.drawable.Drawable; - -/** - * Created by sangcomz on 13/05/2017. - */ - -interface CustomizationProperty { - FishBunCreator setAlbumThumbnailSize(int size); - - FishBunCreator setPickerSpanCount(int spanCount); - - FishBunCreator setActionBarColor(int actionbarColor); - - FishBunCreator setActionBarTitleColor(int actionbarTitleColor); - - FishBunCreator setActionBarColor(int actionbarColor, int statusBarColor); - - FishBunCreator setActionBarColor(int actionbarColor, int statusBarColor, boolean isStatusBarLight); - - FishBunCreator setCamera(boolean isCamera); - - FishBunCreator textOnNothingSelected(String message); - - FishBunCreator textOnImagesSelectionLimitReached(String message); - - FishBunCreator setButtonInAlbumActivity(boolean isButton); - - FishBunCreator setAlbumSpanCount(int portraitSpanCount, int landscapeSpanCount); - - FishBunCreator setAlbumSpanCountOnlyLandscape(int landscapeSpanCount); - - FishBunCreator setAlbumSpanCountOnlPortrait(int portraitSpanCount); - - FishBunCreator setAllViewTitle(String allViewTitle); - - FishBunCreator setActionBarTitle(String actionBarTitle); - - FishBunCreator setHomeAsUpIndicatorDrawable(Drawable icon); - - FishBunCreator setDoneButtonDrawable(Drawable icon); - - FishBunCreator setAllDoneButtonDrawable(Drawable icon); - - FishBunCreator setIsUseAllDoneButton(Boolean isUse); - - FishBunCreator setMenuDoneText(String text); - - FishBunCreator setMenuAllDoneText(String text); - - FishBunCreator setMenuTextColor(int color); - - FishBunCreator setIsUseDetailView(boolean isUse); - - FishBunCreator setIsShowCount(boolean isShow); - - FishBunCreator setSelectCircleStrokeColor(int strokeColor); - - FishBunCreator isStartInAllView(boolean isStartInAllView); -} diff --git a/FishBun/src/main/java/com/sangcomz/fishbun/CustomizationProperty.kt b/FishBun/src/main/java/com/sangcomz/fishbun/CustomizationProperty.kt new file mode 100644 index 00000000..b42b50db --- /dev/null +++ b/FishBun/src/main/java/com/sangcomz/fishbun/CustomizationProperty.kt @@ -0,0 +1,60 @@ +package com.sangcomz.fishbun + +import android.graphics.drawable.Drawable + +/** + * Created by sangcomz on 13/05/2017. + */ +interface CustomizationProperty { + fun setAlbumThumbnailSize(size: Int): FishBunCreator + + fun setPickerSpanCount(spanCount: Int): FishBunCreator + + fun setActionBarColor(actionbarColor: Int): FishBunCreator + + fun setActionBarTitleColor(actionbarTitleColor: Int): FishBunCreator + + fun setActionBarColor(actionbarColor: Int, statusBarColor: Int): FishBunCreator + + fun setActionBarColor(actionbarColor: Int, statusBarColor: Int, isStatusBarLight: Boolean): FishBunCreator + + fun setCamera(isCamera: Boolean): FishBunCreator + + fun textOnNothingSelected(message: String?): FishBunCreator + + fun textOnImagesSelectionLimitReached(message: String?): FishBunCreator + + fun setButtonInAlbumActivity(isButton: Boolean): FishBunCreator + + fun setAlbumSpanCount(portraitSpanCount: Int, landscapeSpanCount: Int): FishBunCreator + + fun setAlbumSpanCountOnlyLandscape(landscapeSpanCount: Int): FishBunCreator + + fun setAlbumSpanCountOnlPortrait(portraitSpanCount: Int): FishBunCreator + + fun setAllViewTitle(allViewTitle: String?): FishBunCreator + + fun setActionBarTitle(actionBarTitle: String?): FishBunCreator + + fun setHomeAsUpIndicatorDrawable(icon: Drawable?): FishBunCreator + + fun setDoneButtonDrawable(icon: Drawable?): FishBunCreator + + fun setAllDoneButtonDrawable(icon: Drawable?): FishBunCreator + + fun setIsUseAllDoneButton(isUse: Boolean): FishBunCreator + + fun setMenuDoneText(text: String?): FishBunCreator + + fun setMenuAllDoneText(text: String?): FishBunCreator + + fun setMenuTextColor(color: Int): FishBunCreator + + fun setIsUseDetailView(isUse: Boolean): FishBunCreator + + fun setIsShowCount(isShow: Boolean): FishBunCreator + + fun setSelectCircleStrokeColor(strokeColor: Int): FishBunCreator + + fun isStartInAllView(isStartInAllView: Boolean): FishBunCreator +} \ No newline at end of file diff --git a/FishBun/src/main/java/com/sangcomz/fishbun/FishBun.java b/FishBun/src/main/java/com/sangcomz/fishbun/FishBun.java deleted file mode 100644 index e80454ff..00000000 --- a/FishBun/src/main/java/com/sangcomz/fishbun/FishBun.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.sangcomz.fishbun; - -import android.app.Activity; -import androidx.fragment.app.Fragment; - -import com.sangcomz.fishbun.adapter.image.ImageAdapter; - -import java.lang.ref.WeakReference; - - -public final class FishBun { - - protected WeakReference activity = null; - protected WeakReference fragment = null; - - - public static FishBun with(Activity activity) { - return new FishBun(activity, null); - } - - public static FishBun with(Fragment fragment) { - return new FishBun(null, fragment); - } - - - FishBun(Activity activity, Fragment fragment) { - this.activity = new WeakReference<>(activity); - this.fragment = new WeakReference<>(fragment); - } - - public FishBunCreator setImageAdapter(ImageAdapter imageAdapter) { - Fishton fishton = Fishton.getInstance(); - fishton.refresh(); - - fishton.imageAdapter = imageAdapter; - return new FishBunCreator(this); - } -} diff --git a/FishBun/src/main/java/com/sangcomz/fishbun/FishBun.kt b/FishBun/src/main/java/com/sangcomz/fishbun/FishBun.kt new file mode 100644 index 00000000..922478b5 --- /dev/null +++ b/FishBun/src/main/java/com/sangcomz/fishbun/FishBun.kt @@ -0,0 +1,30 @@ +package com.sangcomz.fishbun + +import android.app.Activity +import androidx.fragment.app.Fragment +import com.sangcomz.fishbun.adapter.image.ImageAdapter +import java.lang.ref.WeakReference + +class FishBun private constructor(context: Activity?) { + + private val _context: WeakReference = WeakReference(context) + + val context: Activity? + get() = _context.get() + + fun setImageAdapter(imageAdapter: ImageAdapter): FishBunCreator { + val fishton = Fishton.getInstance().apply { + refresh() + this.imageAdapter = imageAdapter + } + return FishBunCreator(this, fishton) + } + + companion object { + @JvmStatic + fun with(activity: Activity) = FishBun(activity) + + @JvmStatic + fun with(fragment: Fragment) = FishBun(fragment.activity) + } +} \ No newline at end of file diff --git a/FishBun/src/main/java/com/sangcomz/fishbun/FishBunCreator.java b/FishBun/src/main/java/com/sangcomz/fishbun/FishBunCreator.java deleted file mode 100644 index 1417f5d1..00000000 --- a/FishBun/src/main/java/com/sangcomz/fishbun/FishBunCreator.java +++ /dev/null @@ -1,281 +0,0 @@ -package com.sangcomz.fishbun; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.graphics.drawable.Drawable; -import android.net.Uri; -import androidx.fragment.app.Fragment; - -import com.sangcomz.fishbun.bean.Album; -import com.sangcomz.fishbun.define.Define; -import com.sangcomz.fishbun.ui.album.AlbumActivity; -import com.sangcomz.fishbun.ui.picker.PickerActivity; - -import java.util.ArrayList; - -/** - * Created by sangcomz on 17/05/2017. - */ - -public final class FishBunCreator implements BaseProperty, CustomizationProperty { - - private FishBun fishBun; - private Fishton fishton; - - private int requestCode = 27; - - - FishBunCreator(FishBun fishBun) { - this.fishBun = fishBun; - this.fishton = Fishton.getInstance(); - } - - public FishBunCreator setSelectedImages(ArrayList selectedImages) { - fishton.selectedImages = selectedImages; - return this; - } - - public FishBunCreator setAlbumThumbnailSize(int size) { - fishton.albumThumbnailSize = size; - return this; - } - - @Override - public FishBunCreator setPickerSpanCount(int spanCount) { - if (spanCount <= 0) - spanCount = 3; - - fishton.photoSpanCount = spanCount; - return this; - - } - - @Deprecated - @Override - public FishBunCreator setPickerCount(int count) { - if (count <= 0) - count = 1; - - fishton.maxCount = count; - - return this; - } - - @Override - public FishBunCreator setMaxCount(int count) { - if (count <= 0) - count = 1; - - fishton.maxCount = count; - return this; - } - - @Override - public FishBunCreator setMinCount(int count) { - if (count <= 0) - count = 1; - fishton.minCount = count; - return this; - } - - @Override - public FishBunCreator setActionBarColor(int actionbarColor) { - fishton.colorActionBar = actionbarColor; - return this; - } - - @Override - public FishBunCreator setActionBarTitleColor(int actionbarTitleColor) { - fishton.colorActionBarTitle = actionbarTitleColor; - return this; - } - - @Override - public FishBunCreator setActionBarColor(int actionbarColor, int statusBarColor) { - fishton.colorActionBar = actionbarColor; - fishton.colorStatusBar = statusBarColor; - return this; - } - - @Override - public FishBunCreator setActionBarColor(int actionbarColor, int statusBarColor, boolean isStatusBarLight) { - fishton.colorActionBar = actionbarColor; - fishton.colorStatusBar = statusBarColor; - fishton.isStatusBarLight = isStatusBarLight; - return this; - } - - @Override - public FishBunCreator setCamera(boolean isCamera) { - fishton.isCamera = isCamera; - return this; - } - - @Override - public FishBunCreator setRequestCode(int requestCode) { - this.requestCode = requestCode; - return this; - } - - @Override - public FishBunCreator textOnNothingSelected(String message) { - fishton.messageNothingSelected = message; - return this; - } - - @Override - public FishBunCreator textOnImagesSelectionLimitReached(String message) { - fishton.messageLimitReached = message; - return this; - } - - @Override - public FishBunCreator setButtonInAlbumActivity(boolean isButton) { - fishton.isButton = isButton; - return this; - } - - @Override - public FishBunCreator setReachLimitAutomaticClose(boolean isAutomaticClose) { - fishton.isAutomaticClose = isAutomaticClose; - return this; - } - - @Override - public FishBunCreator setAlbumSpanCount(int portraitSpanCount, int landscapeSpanCount) { - fishton.albumPortraitSpanCount = portraitSpanCount; - fishton.albumLandscapeSpanCount = landscapeSpanCount; - return this; - } - - @Override - public FishBunCreator setAlbumSpanCountOnlyLandscape(int landscapeSpanCount) { - fishton.albumLandscapeSpanCount = landscapeSpanCount; - return this; - } - - @Override - public FishBunCreator setAlbumSpanCountOnlPortrait(int portraitSpanCount) { - fishton.albumPortraitSpanCount = portraitSpanCount; - return this; - } - - @Override - public FishBunCreator setAllViewTitle(String allViewTitle) { - fishton.titleAlbumAllView = allViewTitle; - return this; - } - - @Override - public FishBunCreator setActionBarTitle(String actionBarTitle) { - fishton.titleActionBar = actionBarTitle; - return this; - } - - @Override - public FishBunCreator setHomeAsUpIndicatorDrawable(Drawable icon) { - fishton.drawableHomeAsUpIndicator = icon; - return this; - } - - @Override - public FishBunCreator setDoneButtonDrawable(Drawable icon) { - fishton.drawableDoneButton = icon; - return this; - } - - public FishBunCreator setAllDoneButtonDrawable(Drawable icon) { - fishton.drawableAllDoneButton = icon; - return this; - } - - public FishBunCreator setIsUseAllDoneButton(Boolean isUse){ - fishton.isUseAllDoneButton = isUse; - return this; - } - - @Override - public FishBunCreator exceptGif(boolean isExcept) { - fishton.isExceptGif = isExcept; - return this; - } - - @Override - public FishBunCreator setMenuDoneText(String text) { - fishton.strDoneMenu = text; - return this; - } - - public FishBunCreator setMenuAllDoneText(String text){ - fishton.strAllDoneMenu = text; - return this; - } - - @Override - public FishBunCreator setMenuTextColor(int textColor) { - fishton.colorTextMenu = textColor; - return this; - } - - @Override - public FishBunCreator setIsUseDetailView(boolean isUse) { - fishton.isUseDetailView = isUse; - return this; - } - - @Override - public FishBunCreator setIsShowCount(boolean isShow) { - fishton.isShowCount = isShow; - return this; - } - - @Override - public FishBunCreator setSelectCircleStrokeColor(int strokeColor) { - fishton.colorSelectCircleStroke = strokeColor; - return this; - } - - @Override - public FishBunCreator isStartInAllView(boolean isStartInAllView) { - fishton.isStartInAllView = isStartInAllView; - return this; - } - - @Override - public void startAlbum() { - Context context = null; - Activity activity = fishBun.activity.get(); - Fragment fragment = fishBun.fragment.get(); - if (activity != null) - context = activity; - else if (fragment != null) - context = fragment.getActivity(); - else - try { - throw new NullPointerException("Activity or Fragment Null"); - } catch (Exception e) { - e.printStackTrace(); - } - - if (fishton.imageAdapter == null) - throw new NullPointerException("ImageAdapter is Null"); - - fishton.setDefaultMessage(context); - fishton.setMenuTextColor(); - fishton.setDefaultDimen(context); - - if (fishton.isStartInAllView) { - Intent i = new Intent(context, PickerActivity.class); - i.putExtra(Define.BUNDLE_NAME.ALBUM.name(), new Album(0, fishton.titleAlbumAllView, null, 0)); - i.putExtra(Define.BUNDLE_NAME.POSITION.name(), 0); - if (activity != null) activity.startActivityForResult(i, requestCode); - else if (fragment != null) fragment.startActivityForResult(i, requestCode); - } else { - Intent i = new Intent(context, AlbumActivity.class); - if (activity != null) activity.startActivityForResult(i, requestCode); - else if (fragment != null) fragment.startActivityForResult(i, requestCode); - } - - } -} \ No newline at end of file diff --git a/FishBun/src/main/java/com/sangcomz/fishbun/FishBunCreator.kt b/FishBun/src/main/java/com/sangcomz/fishbun/FishBunCreator.kt new file mode 100644 index 00000000..cbb9d1d5 --- /dev/null +++ b/FishBun/src/main/java/com/sangcomz/fishbun/FishBunCreator.kt @@ -0,0 +1,174 @@ +package com.sangcomz.fishbun + +import android.content.Intent +import android.graphics.drawable.Drawable +import android.net.Uri +import com.sangcomz.fishbun.bean.Album +import com.sangcomz.fishbun.define.Define +import com.sangcomz.fishbun.ui.album.AlbumActivity +import com.sangcomz.fishbun.ui.picker.PickerActivity +import java.util.* + +/** + * Created by sangcomz on 17/05/2017. + */ +class FishBunCreator(private val fishBun: FishBun, private val fishton: Fishton) : BaseProperty, CustomizationProperty { + private var requestCode = 27 + + override fun setSelectedImages(selectedImages: ArrayList): FishBunCreator = this.apply { + fishton.selectedImages = selectedImages + } + + override fun setAlbumThumbnailSize(size: Int): FishBunCreator = apply { + fishton.albumThumbnailSize = size + } + + override fun setPickerSpanCount(spanCount: Int): FishBunCreator = this.apply { + fishton.photoSpanCount = if (spanCount <= 0) 3 else spanCount + } + + @Deprecated("instead setMaxCount(count)", ReplaceWith("setPickerCount(count)")) + override fun setPickerCount(count: Int): FishBunCreator = this.apply { + setMaxCount(count) + } + + override fun setMaxCount(count: Int): FishBunCreator = this.apply { + fishton.maxCount = if (count <= 0) 1 else count + } + + override fun setMinCount(count: Int): FishBunCreator = this.apply { + fishton.minCount = if (count <= 0) 1 else count + } + + override fun setActionBarTitleColor(actionbarTitleColor: Int): FishBunCreator = this.apply { + fishton.colorActionBarTitle = actionbarTitleColor + } + + override fun setActionBarColor(actionbarColor: Int): FishBunCreator = this.apply { + fishton.colorActionBar = actionbarColor + } + + override fun setActionBarColor(actionbarColor: Int, statusBarColor: Int): FishBunCreator = this.apply { + fishton.colorActionBar = actionbarColor + fishton.colorStatusBar = statusBarColor + } + + override fun setActionBarColor(actionbarColor: Int, statusBarColor: Int, isStatusBarLight: Boolean): FishBunCreator = this.apply { + fishton.colorActionBar = actionbarColor + fishton.colorStatusBar = statusBarColor + fishton.isStatusBarLight = isStatusBarLight + } + + override fun setCamera(isCamera: Boolean): FishBunCreator = this.apply { + fishton.isCamera = isCamera + } + + override fun setRequestCode(requestCode: Int): FishBunCreator = this.apply { + this.requestCode = requestCode + } + + override fun textOnNothingSelected(message: String?): FishBunCreator = this.apply { + fishton.messageNothingSelected = message + } + + override fun textOnImagesSelectionLimitReached(message: String?): FishBunCreator = this.apply { + fishton.messageLimitReached = message + } + + override fun setButtonInAlbumActivity(isButton: Boolean): FishBunCreator = this.apply { + fishton.isButton = isButton + } + + override fun setReachLimitAutomaticClose(isAutomaticClose: Boolean): FishBunCreator = this.apply { + fishton.isAutomaticClose = isAutomaticClose + } + + override fun setAlbumSpanCount(portraitSpanCount: Int, landscapeSpanCount: Int): FishBunCreator = this.apply { + fishton.albumPortraitSpanCount = portraitSpanCount + fishton.albumLandscapeSpanCount = landscapeSpanCount + } + + override fun setAlbumSpanCountOnlyLandscape(landscapeSpanCount: Int): FishBunCreator = this.apply { + fishton.albumLandscapeSpanCount = landscapeSpanCount + } + + override fun setAlbumSpanCountOnlPortrait(portraitSpanCount: Int): FishBunCreator = this.apply { + fishton.albumPortraitSpanCount = portraitSpanCount + } + + override fun setAllViewTitle(allViewTitle: String?): FishBunCreator = this.apply { + fishton.titleAlbumAllView = allViewTitle + } + + override fun setActionBarTitle(actionBarTitle: String?): FishBunCreator = this.apply { + fishton.titleActionBar = actionBarTitle + } + + override fun setHomeAsUpIndicatorDrawable(icon: Drawable?): FishBunCreator = this.apply { + fishton.drawableHomeAsUpIndicator = icon + } + + override fun setDoneButtonDrawable(icon: Drawable?): FishBunCreator = this.apply { + fishton.drawableDoneButton = icon + } + + override fun setAllDoneButtonDrawable(icon: Drawable?): FishBunCreator = this.apply { + fishton.drawableAllDoneButton = icon + } + + override fun setIsUseAllDoneButton(isUse: Boolean): FishBunCreator = this.apply { + fishton.isUseAllDoneButton = isUse + } + + override fun exceptGif(isExcept: Boolean): FishBunCreator = this.apply { + fishton.isExceptGif = isExcept + } + + override fun setMenuDoneText(text: String?): FishBunCreator = this.apply { + fishton.strDoneMenu = text + } + + override fun setMenuAllDoneText(text: String?): FishBunCreator = this.apply { + fishton.strAllDoneMenu = text + } + + override fun setMenuTextColor(color: Int): FishBunCreator = this.apply { + fishton.colorTextMenu = color + } + + override fun setIsUseDetailView(isUse: Boolean): FishBunCreator = this.apply { + fishton.isUseDetailView = isUse + } + + override fun setIsShowCount(isShow: Boolean): FishBunCreator = this.apply { + fishton.isShowCount = isShow + } + + override fun setSelectCircleStrokeColor(strokeColor: Int): FishBunCreator = this.apply { + fishton.colorSelectCircleStroke = strokeColor + } + + override fun isStartInAllView(isStartInAllView: Boolean): FishBunCreator = this.apply { + fishton.isStartInAllView = isStartInAllView + } + + override fun startAlbum() = + fishBun.context?.let { context -> + with(fishton) { + setDefaultMessage(context) + setMenuTextColor() + setDefaultDimen(context) + } + val intent: Intent = + if (fishton.isStartInAllView) { + Intent(context, PickerActivity::class.java).apply { + putExtra(Define.BUNDLE_NAME.ALBUM.name, Album(0, fishton.titleAlbumAllView, null, 0)) + putExtra(Define.BUNDLE_NAME.POSITION.name, 0) + } + } else { + Intent(context, AlbumActivity::class.java) + } + context.startActivityForResult(intent, requestCode) + } ?: throw NullPointerException("Activity or Fragment Null") +} + diff --git a/FishBun/src/main/java/com/sangcomz/fishbun/Fishton.java b/FishBun/src/main/java/com/sangcomz/fishbun/Fishton.java deleted file mode 100644 index 8e869195..00000000 --- a/FishBun/src/main/java/com/sangcomz/fishbun/Fishton.java +++ /dev/null @@ -1,163 +0,0 @@ -package com.sangcomz.fishbun; - -import android.content.Context; -import android.graphics.Color; -import android.graphics.drawable.Drawable; -import android.net.Uri; - -import com.sangcomz.fishbun.adapter.image.ImageAdapter; - -import java.util.ArrayList; - -/** - * Created by seokwon.jeong on 04/01/2018. - */ - -public class Fishton { - public ImageAdapter imageAdapter; - public Uri[] pickerImages; - - //BaseParams - public int maxCount; - public int minCount; - public boolean isExceptGif; - public ArrayList selectedImages = new ArrayList<>(); - - - //CustomizationParams - public int photoSpanCount; - public int albumPortraitSpanCount; - public int albumLandscapeSpanCount; - - public boolean isAutomaticClose; - public boolean isButton; - - public int colorActionBar; - public int colorActionBarTitle; - public int colorStatusBar; - - public boolean isStatusBarLight; - public boolean isCamera; - - public int albumThumbnailSize; - - public String messageNothingSelected; - public String messageLimitReached; - public String titleAlbumAllView; - public String titleActionBar; - - public Drawable drawableHomeAsUpIndicator; - public Drawable drawableDoneButton; - public Drawable drawableAllDoneButton; - public boolean isUseAllDoneButton; - - public String strDoneMenu; - public String strAllDoneMenu; - - public int colorTextMenu; - - public boolean isUseDetailView; - - public boolean isShowCount; - - public int colorSelectCircleStroke; - - public boolean isStartInAllView; - - - private Fishton() { - init(); - } - - public static Fishton getInstance() { - return FishtonHolder.INSTANCE; - } - - private static class FishtonHolder { - public static final Fishton INSTANCE = new Fishton(); - } - - public void refresh() { - init(); - } - - private void init() { - //Adapter - imageAdapter = null; - - //BaseParams - maxCount = 10; - minCount = 1; - isExceptGif = true; - selectedImages = new ArrayList<>(); - - //CustomizationParams - photoSpanCount = 3; - albumPortraitSpanCount = 1; - albumLandscapeSpanCount = 2; - - isAutomaticClose = false; - isButton = false; - - colorActionBar = Color.parseColor("#3F51B5"); - colorActionBarTitle = Color.parseColor("#ffffff"); - colorStatusBar = Color.parseColor("#303F9F"); - - isStatusBarLight = false; - isCamera = false; - - albumThumbnailSize = Integer.MAX_VALUE; - - messageNothingSelected = null; - messageLimitReached = null; - titleAlbumAllView = null; - titleActionBar = null; - - drawableHomeAsUpIndicator = null; - drawableDoneButton = null; - drawableAllDoneButton = null; - - strDoneMenu = null; - strAllDoneMenu = null; - - - colorTextMenu = Integer.MAX_VALUE; - - isUseAllDoneButton = false; - isUseDetailView = true; - isShowCount = true; - - colorSelectCircleStroke = Color.parseColor("#c1ffffff"); - isStartInAllView = false; - } - - void setDefaultMessage(Context context) { - if (messageNothingSelected == null) - messageNothingSelected = context.getResources().getString(R.string.msg_no_selected); - - if (messageLimitReached == null) - messageLimitReached = context.getResources().getString(R.string.msg_full_image); - - if (titleAlbumAllView == null) - titleAlbumAllView = context.getResources().getString(R.string.str_all_view); - - if (titleActionBar == null) - titleActionBar = context.getResources().getString(R.string.album); - } - - void setMenuTextColor() { - if (drawableDoneButton != null - || drawableAllDoneButton != null - || strDoneMenu == null - || colorTextMenu != Integer.MAX_VALUE) - return; - - if (isStatusBarLight) - colorTextMenu = Color.BLACK; - } - - void setDefaultDimen(Context context) { - if (albumThumbnailSize == Integer.MAX_VALUE) - albumThumbnailSize = (int) context.getResources().getDimension(R.dimen.album_thum_size); - } -} diff --git a/FishBun/src/main/java/com/sangcomz/fishbun/Fishton.kt b/FishBun/src/main/java/com/sangcomz/fishbun/Fishton.kt new file mode 100644 index 00000000..61cb7b06 --- /dev/null +++ b/FishBun/src/main/java/com/sangcomz/fishbun/Fishton.kt @@ -0,0 +1,155 @@ +package com.sangcomz.fishbun + +import android.content.Context +import android.graphics.Color +import android.graphics.drawable.Drawable +import android.net.Uri +import com.sangcomz.fishbun.adapter.image.ImageAdapter +import com.sangcomz.fishbun.util.getDimension +import java.util.ArrayList + +/** + * Created by seokwon.jeong on 04/01/2018. + */ +class Fishton { + var imageAdapter: ImageAdapter? = null + var pickerImages: Array? = null + + //BaseParams + var maxCount: Int = 0 + var minCount: Int = 0 + var isExceptGif: Boolean = false + var selectedImages = ArrayList() + + //CustomizationParams + var photoSpanCount: Int = 0 + var albumPortraitSpanCount: Int = 0 + var albumLandscapeSpanCount: Int = 0 + + var isAutomaticClose: Boolean = false + var isButton: Boolean = false + + var colorActionBar: Int = 0 + var colorActionBarTitle: Int = 0 + var colorStatusBar: Int = 0 + + var isStatusBarLight: Boolean = false + var isCamera: Boolean = false + + var albumThumbnailSize: Int = 0 + + var messageNothingSelected: String? = null + var messageLimitReached: String? = null + var titleAlbumAllView: String? = null + var titleActionBar: String? = null + + var drawableHomeAsUpIndicator: Drawable? = null + var drawableDoneButton: Drawable? = null + var drawableAllDoneButton: Drawable? = null + var isUseAllDoneButton: Boolean = false + + var strDoneMenu: String? = null + var strAllDoneMenu: String? = null + + var colorTextMenu: Int = 0 + + var isUseDetailView: Boolean = false + + var isShowCount: Boolean = false + + var colorSelectCircleStroke: Int = 0 + + var isStartInAllView: Boolean = false + + init { + init() + } + + fun refresh() = init() + + private fun init() { + //Adapter + imageAdapter = null + + //BaseParams + maxCount = 10 + minCount = 1 + isExceptGif = true + selectedImages = ArrayList() + + //CustomizationParams + photoSpanCount = 3 + albumPortraitSpanCount = 1 + albumLandscapeSpanCount = 2 + + isAutomaticClose = false + isButton = false + + colorActionBar = Color.parseColor("#3F51B5") + colorActionBarTitle = Color.parseColor("#ffffff") + colorStatusBar = Color.parseColor("#303F9F") + + isStatusBarLight = false + isCamera = false + + albumThumbnailSize = Integer.MAX_VALUE + + drawableHomeAsUpIndicator = null + drawableDoneButton = null + drawableAllDoneButton = null + + strDoneMenu = null + strAllDoneMenu = null + + colorTextMenu = Integer.MAX_VALUE + + isUseAllDoneButton = false + isUseDetailView = true + isShowCount = true + + colorSelectCircleStroke = Color.parseColor("#c1ffffff") + isStartInAllView = false + } + + fun setDefaultMessage(context: Context) { + messageNothingSelected = + messageNothingSelected ?: context.getString(R.string.msg_no_selected) + + messageLimitReached = + messageLimitReached ?: context.getString(R.string.msg_full_image) + + titleAlbumAllView = + titleAlbumAllView ?: context.getString(R.string.str_all_view) + + titleActionBar = + titleActionBar ?: context.getString(R.string.album) + } + + fun setMenuTextColor() { + if (drawableDoneButton != null + || drawableAllDoneButton != null + || strDoneMenu == null + || colorTextMenu != Integer.MAX_VALUE) + return + + colorTextMenu = if (isStatusBarLight) Color.BLACK else colorTextMenu + } + + fun setDefaultDimen(context: Context) { + albumThumbnailSize = + if (albumThumbnailSize == Int.MAX_VALUE) { + context.getDimension(R.dimen.album_thum_size) + } else { + albumThumbnailSize + } + } + + private object FishtonHolder { + val INSTANCE = Fishton() + } + + companion object { + @JvmStatic + fun getInstance() = FishtonHolder.INSTANCE + } +} \ No newline at end of file diff --git a/FishBun/src/main/java/com/sangcomz/fishbun/adapter/view/AlbumListAdapter.java b/FishBun/src/main/java/com/sangcomz/fishbun/adapter/view/AlbumListAdapter.java index c0870093..75d21276 100644 --- a/FishBun/src/main/java/com/sangcomz/fishbun/adapter/view/AlbumListAdapter.java +++ b/FishBun/src/main/java/com/sangcomz/fishbun/adapter/view/AlbumListAdapter.java @@ -42,7 +42,7 @@ public void setAlbumList(List albumList) { public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.album_item, parent, false); - return new ViewHolder(view, fishton.albumThumbnailSize); + return new ViewHolder(view, fishton.getAlbumThumbnailSize()); } @Override @@ -52,7 +52,7 @@ public void onBindViewHolder(@NonNull final ViewHolder holder, final int positio Uri loadUrl = Uri.parse(albumList.get(position).thumbnailPath); if (holder.imgAlbumThumb != null && loadUrl != null) - Fishton.getInstance().imageAdapter + Fishton.getInstance().getImageAdapter() .loadImage(holder.imgAlbumThumb, loadUrl); holder.view.setTag(albumList.get(position)); diff --git a/FishBun/src/main/java/com/sangcomz/fishbun/adapter/view/DetailViewPagerAdapter.java b/FishBun/src/main/java/com/sangcomz/fishbun/adapter/view/DetailViewPagerAdapter.java index b95ed4ac..b48db649 100644 --- a/FishBun/src/main/java/com/sangcomz/fishbun/adapter/view/DetailViewPagerAdapter.java +++ b/FishBun/src/main/java/com/sangcomz/fishbun/adapter/view/DetailViewPagerAdapter.java @@ -42,7 +42,7 @@ public Object instantiateItem(@NonNull ViewGroup container, int position) { if (imageView != null && images[position] != null) fishton - .imageAdapter + .getImageAdapter() .loadDetailImage(imageView, images[position]); return itemView; diff --git a/FishBun/src/main/java/com/sangcomz/fishbun/adapter/view/PickerGridAdapter.java b/FishBun/src/main/java/com/sangcomz/fishbun/adapter/view/PickerGridAdapter.java index d0778c3e..ff206ad7 100644 --- a/FishBun/src/main/java/com/sangcomz/fishbun/adapter/view/PickerGridAdapter.java +++ b/FishBun/src/main/java/com/sangcomz/fishbun/adapter/view/PickerGridAdapter.java @@ -79,22 +79,22 @@ public void onClick(View v) { if (holder instanceof ViewHolderImage) { final int imagePos; - if (fishton.isCamera) imagePos = position - 1; + if (fishton.isCamera()) imagePos = position - 1; else imagePos = position; final ViewHolderImage vh = (ViewHolderImage) holder; - final Uri image = fishton.pickerImages[imagePos]; + final Uri image = fishton.getPickerImages()[imagePos]; final Context context = vh.item.getContext(); vh.item.setTag(image); vh.btnThumbCount.unselect(); - vh.btnThumbCount.setCircleColor(fishton.colorActionBar); - vh.btnThumbCount.setTextColor(fishton.colorActionBarTitle); - vh.btnThumbCount.setStrokeColor(fishton.colorSelectCircleStroke); + vh.btnThumbCount.setCircleColor(fishton.getColorActionBar()); + vh.btnThumbCount.setTextColor(fishton.getColorActionBarTitle()); + vh.btnThumbCount.setStrokeColor(fishton.getColorSelectCircleStroke()); - initState(fishton.selectedImages.indexOf(image), vh); + initState(fishton.getSelectedImages().indexOf(image), vh); if (image != null && vh.imgThumbImage != null) - Fishton.getInstance().imageAdapter + Fishton.getInstance().getImageAdapter() .loadImage(vh.imgThumbImage, image); @@ -108,7 +108,7 @@ public void onClick(View v) { vh.imgThumbImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (fishton.isUseDetailView) { + if (fishton.isUseDetailView()) { if (context instanceof PickerActivity) { PickerActivity activity = (PickerActivity) context; Intent i = new Intent(activity, DetailActivity.class); @@ -133,11 +133,11 @@ private void initState(int selectedIndex, ViewHolderImage vh) { } private void onCheckStateChange(View v, Uri image) { - ArrayList pickedImages = fishton.selectedImages; + ArrayList pickedImages = fishton.getSelectedImages(); boolean isContained = pickedImages.contains(image); - if (fishton.maxCount == pickedImages.size() + if (fishton.getMaxCount() == pickedImages.size() && !isContained) { - Snackbar.make(v, fishton.messageLimitReached, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(v, fishton.getMessageLimitReached(), Snackbar.LENGTH_SHORT).show(); return; } ImageView imgThumbImage = v.findViewById(R.id.img_thumb_image); @@ -149,8 +149,8 @@ private void onCheckStateChange(View v, Uri image) { } else { animScale(imgThumbImage, true, true); pickedImages.add(image); - if (fishton.isAutomaticClose - && fishton.maxCount == pickedImages.size()) { + if (fishton.isAutomaticClose() + && fishton.getMaxCount() == pickedImages.size()) { pickerController.finishActivity(); } updateRadioButton(btnThumbCount, String.valueOf(pickedImages.size())); @@ -159,7 +159,7 @@ private void onCheckStateChange(View v, Uri image) { } public void updateRadioButton(RadioWithTextButton v, String text) { - if (fishton.maxCount == 1) + if (fishton.getMaxCount() == 1) v.setDrawable(ContextCompat.getDrawable(v.getContext(), R.drawable.ic_done_white_24dp)); else v.setText(text); @@ -168,7 +168,7 @@ public void updateRadioButton(RadioWithTextButton v, String text) { public void updateRadioButton(ImageView imageView, RadioWithTextButton v, String text, boolean isSelected) { if (isSelected) { animScale(imageView, isSelected, false); - if (fishton.maxCount == 1) + if (fishton.getMaxCount() == 1) v.setDrawable(ContextCompat.getDrawable(v.getContext(), R.drawable.ic_done_white_24dp)); else v.setText(text); @@ -213,19 +213,19 @@ public void run() { @Override public int getItemCount() { int count; - if (fishton.pickerImages == null) count = 0; - else count = fishton.pickerImages.length; + if (fishton.getPickerImages() == null) count = 0; + else count = fishton.getPickerImages().length; - if (fishton.isCamera) + if (fishton.isCamera()) return count + 1; - if (fishton.pickerImages == null) return 0; + if (fishton.getPickerImages() == null) return 0; else return count; } @Override public int getItemViewType(int position) { - if (position == 0 && fishton.isCamera) { + if (position == 0 && fishton.isCamera()) { return TYPE_HEADER; } return super.getItemViewType(position); @@ -234,9 +234,9 @@ public int getItemViewType(int position) { public void addImage(Uri path) { ArrayList al = new ArrayList<>(); - Collections.addAll(al, fishton.pickerImages); + Collections.addAll(al, fishton.getPickerImages()); al.add(0, path); - fishton.pickerImages = al.toArray(new Uri[al.size()]); + fishton.setPickerImages(al.toArray(new Uri[al.size()])); notifyDataSetChanged(); diff --git a/FishBun/src/main/java/com/sangcomz/fishbun/ui/album/AlbumActivity.java b/FishBun/src/main/java/com/sangcomz/fishbun/ui/album/AlbumActivity.java index dbccf394..c6a7a6cb 100644 --- a/FishBun/src/main/java/com/sangcomz/fishbun/ui/album/AlbumActivity.java +++ b/FishBun/src/main/java/com/sangcomz/fishbun/ui/album/AlbumActivity.java @@ -60,7 +60,7 @@ protected void onRestoreInstanceState(Bundle outState) { List albumList = outState.getParcelableArrayList(define.SAVE_INSTANCE_ALBUM_LIST); List thumbList = outState.getParcelableArrayList(define.SAVE_INSTANCE_ALBUM_THUMB_LIST); - if (albumList != null && thumbList != null && fishton.selectedImages != null) { + if (albumList != null && thumbList != null && fishton.getSelectedImages() != null) { adapter = new AlbumListAdapter(); adapter.setAlbumList(albumList); } @@ -73,7 +73,7 @@ public void onCreate(Bundle savedInstanceState) { initView(); initController(); if (albumController.checkPermission()) - albumController.getAlbumList(fishton.titleAlbumAllView, fishton.isExceptGif); + albumController.getAlbumList(fishton.getTitleAlbumAllView(), fishton.isExceptGif()); } @Override @@ -83,10 +83,10 @@ protected void onResume() { recyclerAlbumList.getLayoutManager() != null) { if (uiUtil.isLandscape(this)) ((GridLayoutManager) recyclerAlbumList.getLayoutManager()) - .setSpanCount(fishton.albumLandscapeSpanCount); + .setSpanCount(fishton.getAlbumLandscapeSpanCount()); else ((GridLayoutManager) recyclerAlbumList.getLayoutManager()) - .setSpanCount(fishton.albumPortraitSpanCount); + .setSpanCount(fishton.getAlbumPortraitSpanCount()); } } @@ -109,9 +109,9 @@ private void initRecyclerView() { GridLayoutManager layoutManager; if (uiUtil.isLandscape(this)) - layoutManager = new GridLayoutManager(this, fishton.albumLandscapeSpanCount); + layoutManager = new GridLayoutManager(this, fishton.getAlbumLandscapeSpanCount()); else - layoutManager = new GridLayoutManager(this, fishton.albumPortraitSpanCount); + layoutManager = new GridLayoutManager(this, fishton.getAlbumPortraitSpanCount()); if (recyclerAlbumList != null) { recyclerAlbumList.setLayoutManager(layoutManager); @@ -126,20 +126,20 @@ private void initToolBar() { setSupportActionBar(toolbar); - toolbar.setBackgroundColor(fishton.colorActionBar); - toolbar.setTitleTextColor(fishton.colorActionBarTitle); + toolbar.setBackgroundColor(fishton.getColorActionBar()); + toolbar.setTitleTextColor(fishton.getColorActionBarTitle()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - uiUtil.setStatusBarColor(this, fishton.colorStatusBar); + uiUtil.setStatusBarColor(this, fishton.getColorStatusBar()); } if (getSupportActionBar() != null) { - getSupportActionBar().setTitle(fishton.titleActionBar); + getSupportActionBar().setTitle(fishton.getTitleActionBar()); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - if (fishton.drawableHomeAsUpIndicator != null) - getSupportActionBar().setHomeAsUpIndicator(fishton.drawableHomeAsUpIndicator); + if (fishton.getDrawableHomeAsUpIndicator() != null) + getSupportActionBar().setHomeAsUpIndicator(fishton.getDrawableHomeAsUpIndicator()); } - if (fishton.isStatusBarLight + if (fishton.isStatusBarLight() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { toolbar.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); } @@ -175,7 +175,7 @@ protected void setAlbumList(ArrayList albumList) { private void refreshList(int position, ArrayList imagePath) { if (imagePath.size() > 0) { if (position == 0) { - albumController.getAlbumList(fishton.titleAlbumAllView, fishton.isExceptGif); + albumController.getAlbumList(fishton.getTitleAlbumAllView(), fishton.isExceptGif()); } else { albumList.get(0).counter += imagePath.size(); albumList.get(position).counter += imagePath.size(); @@ -192,19 +192,19 @@ private void refreshList(int position, ArrayList imagePath) { @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. - if (fishton.isButton) { + if (fishton.isButton()) { getMenuInflater().inflate(R.menu.menu_photo_album, menu); MenuItem menuDoneItem = menu.findItem(R.id.action_done); menu.findItem(R.id.action_all_done).setVisible(false); - if (fishton.drawableDoneButton != null) { - menuDoneItem.setIcon(fishton.drawableDoneButton); - } else if (fishton.strDoneMenu != null) { - if (fishton.colorTextMenu != Integer.MAX_VALUE) { - SpannableString spanString = new SpannableString(fishton.strDoneMenu); - spanString.setSpan(new ForegroundColorSpan(fishton.colorTextMenu), 0, spanString.length(), 0); //fi + if (fishton.getDrawableDoneButton() != null) { + menuDoneItem.setIcon(fishton.getDrawableDoneButton()); + } else if (fishton.getStrDoneMenu() != null) { + if (fishton.getColorTextMenu() != Integer.MAX_VALUE) { + SpannableString spanString = new SpannableString(fishton.getStrDoneMenu()); + spanString.setSpan(new ForegroundColorSpan(fishton.getColorTextMenu()), 0, spanString.length(), 0); //fi menuDoneItem.setTitle(spanString); } else { - menuDoneItem.setTitle(fishton.strDoneMenu); + menuDoneItem.setTitle(fishton.getStrDoneMenu()); } menuDoneItem.setIcon(null); } @@ -220,8 +220,8 @@ public boolean onOptionsItemSelected(MenuItem item) { finish(); } else if (id == R.id.action_done) { if (adapter != null) { - if (fishton.selectedImages.size() < fishton.minCount) { - Snackbar.make(recyclerAlbumList, fishton.messageNothingSelected, Snackbar.LENGTH_SHORT).show(); + if (fishton.getSelectedImages().size() < fishton.getMinCount()) { + Snackbar.make(recyclerAlbumList, fishton.getMessageNothingSelected(), Snackbar.LENGTH_SHORT).show(); } else { finishActivity(); } @@ -233,13 +233,13 @@ public boolean onOptionsItemSelected(MenuItem item) { public void changeToolbarTitle() { if (adapter == null) return; - int total = fishton.selectedImages.size(); + int total = fishton.getSelectedImages().size(); if (getSupportActionBar() != null) { - if (fishton.maxCount == 1 || !fishton.isShowCount) - getSupportActionBar().setTitle(fishton.titleActionBar); + if (fishton.getMaxCount() == 1 || !fishton.isShowCount()) + getSupportActionBar().setTitle(fishton.getTitleActionBar()); else - getSupportActionBar().setTitle(fishton.titleActionBar + " (" + total + "/" + fishton.maxCount + ")"); + getSupportActionBar().setTitle(fishton.getTitleActionBar() + " (" + total + "/" + fishton.getMaxCount() + ")"); } } @@ -261,7 +261,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { new SingleMediaScanner(this, new File(albumController.getSavePath()), new ScanListener() { @Override protected void onScanCompleted() { - albumController.getAlbumList(fishton.titleAlbumAllView, fishton.isExceptGif); + albumController.getAlbumList(fishton.getTitleAlbumAllView(), fishton.isExceptGif()); } }); } else { @@ -281,7 +281,7 @@ public void onRequestPermissionsResult(int requestCode, if (grantResults.length > 0) { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { // permission was granted, yay! - albumController.getAlbumList(fishton.titleAlbumAllView, fishton.isExceptGif); + albumController.getAlbumList(fishton.getTitleAlbumAllView(), fishton.isExceptGif()); } else { new PermissionCheck(this).showPermissionDialog(); finish(); @@ -306,7 +306,7 @@ public void onRequestPermissionsResult(int requestCode, private void finishActivity() { Intent i = new Intent(); - i.putParcelableArrayListExtra(Define.INTENT_PATH, fishton.selectedImages); + i.putParcelableArrayListExtra(Define.INTENT_PATH, fishton.getSelectedImages()); setResult(RESULT_OK, i); finish(); } diff --git a/FishBun/src/main/java/com/sangcomz/fishbun/ui/detail/DetailActivity.java b/FishBun/src/main/java/com/sangcomz/fishbun/ui/detail/DetailActivity.java index a1d7cafd..91bd1c96 100644 --- a/FishBun/src/main/java/com/sangcomz/fishbun/ui/detail/DetailActivity.java +++ b/FishBun/src/main/java/com/sangcomz/fishbun/ui/detail/DetailActivity.java @@ -50,9 +50,9 @@ private void initView() { vpDetailPager = findViewById(R.id.vp_detail_pager); btnDetailBack = findViewById(R.id.btn_detail_back); btnDetailCount.unselect(); - btnDetailCount.setCircleColor(fishton.colorActionBar); - btnDetailCount.setTextColor(fishton.colorActionBarTitle); - btnDetailCount.setStrokeColor(fishton.colorSelectCircleStroke); + btnDetailCount.setCircleColor(fishton.getColorActionBar()); + btnDetailCount.setTextColor(fishton.getColorActionBarTitle()); + btnDetailCount.setStrokeColor(fishton.getColorSelectCircleStroke()); btnDetailCount.setOnClickListener(this); btnDetailBack.setOnClickListener(this); initToolBar(); @@ -65,9 +65,9 @@ private void initValue() { private void initToolBar() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - uiUtil.setStatusBarColor(this, fishton.colorStatusBar); + uiUtil.setStatusBarColor(this, fishton.getColorStatusBar()); } - if (fishton.isStatusBarLight + if (fishton.isStatusBarLight() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { vpDetailPager.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); } @@ -75,15 +75,15 @@ private void initToolBar() { } private void initAdapter() { - if (fishton.pickerImages == null) { + if (fishton.getPickerImages() == null) { Toast.makeText(this, R.string.msg_error, Toast.LENGTH_SHORT).show(); finish(); return; } - onCheckStateChange(fishton.pickerImages[initPosition]); + onCheckStateChange(fishton.getPickerImages()[initPosition]); - DetailViewPagerAdapter adapter = new DetailViewPagerAdapter(getLayoutInflater(), fishton.pickerImages); + DetailViewPagerAdapter adapter = new DetailViewPagerAdapter(getLayoutInflater(), fishton.getPickerImages()); vpDetailPager.setAdapter(adapter); vpDetailPager.setCurrentItem(initPosition); @@ -91,10 +91,10 @@ private void initAdapter() { } public void onCheckStateChange(Uri image) { - boolean isContained = fishton.selectedImages.contains(image); + boolean isContained = fishton.getSelectedImages().contains(image); if (isContained) { updateRadioButton(btnDetailCount, - String.valueOf(fishton.selectedImages.indexOf(image) + 1)); + String.valueOf(fishton.getSelectedImages().indexOf(image) + 1)); } else { btnDetailCount.unselect(); } @@ -102,7 +102,7 @@ public void onCheckStateChange(Uri image) { public void updateRadioButton(RadioWithTextButton v, String text) { - if (fishton.maxCount == 1) + if (fishton.getMaxCount() == 1) v.setDrawable(ContextCompat.getDrawable(v.getContext(), R.drawable.ic_done_white_24dp)); else v.setText(text); @@ -117,18 +117,18 @@ public void onBackPressed() { public void onClick(View v) { int id = v.getId(); if (id == R.id.btn_detail_count) { - Uri image = fishton.pickerImages[vpDetailPager.getCurrentItem()]; - if (fishton.selectedImages.contains(image)) { - fishton.selectedImages.remove(image); + Uri image = fishton.getPickerImages()[vpDetailPager.getCurrentItem()]; + if (fishton.getSelectedImages().contains(image)) { + fishton.getSelectedImages().remove(image); onCheckStateChange(image); } else { - if (fishton.selectedImages.size() == fishton.maxCount) { - Snackbar.make(v, fishton.messageLimitReached, Snackbar.LENGTH_SHORT).show(); + if (fishton.getSelectedImages().size() == fishton.getMaxCount()) { + Snackbar.make(v, fishton.getMessageLimitReached(), Snackbar.LENGTH_SHORT).show(); } else { - fishton.selectedImages.add(image); + fishton.getSelectedImages().add(image); onCheckStateChange(image); - if (fishton.isAutomaticClose && fishton.selectedImages.size() == fishton.maxCount) + if (fishton.isAutomaticClose() && fishton.getSelectedImages().size() == fishton.getMaxCount()) finishActivity(); } } @@ -145,7 +145,7 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse @Override public void onPageSelected(int position) { - onCheckStateChange(fishton.pickerImages[position]); + onCheckStateChange(fishton.getPickerImages()[position]); } @Override diff --git a/FishBun/src/main/java/com/sangcomz/fishbun/ui/picker/PickerActivity.java b/FishBun/src/main/java/com/sangcomz/fishbun/ui/picker/PickerActivity.java index 945b5417..d6c2b57c 100644 --- a/FishBun/src/main/java/com/sangcomz/fishbun/ui/picker/PickerActivity.java +++ b/FishBun/src/main/java/com/sangcomz/fishbun/ui/picker/PickerActivity.java @@ -71,7 +71,7 @@ protected void onRestoreInstanceState(Bundle outState) { try { ArrayList addImages = outState.getParcelableArrayList(define.SAVE_INSTANCE_NEW_IMAGES); String savedImage = outState.getString(define.SAVE_INSTANCE_SAVED_IMAGE); - setAdapter(fishton.pickerImages); + setAdapter(fishton.getPickerImages()); if (addImages != null) { pickerController.setAddImagePaths(addImages); } @@ -91,7 +91,7 @@ protected void onCreate(Bundle savedInstanceState) { initValue(); initView(); if (pickerController.checkPermission()) - pickerController.displayImage(album.bucketId, fishton.isExceptGif); + pickerController.displayImage(album.bucketId, fishton.isExceptGif()); } @@ -112,7 +112,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { } } else if (requestCode == define.ENTER_DETAIL_REQUEST_CODE) { if (resultCode == RESULT_OK) { - if (fishton.isAutomaticClose && fishton.selectedImages.size() == fishton.maxCount) + if (fishton.isAutomaticClose() && fishton.getSelectedImages().size() == fishton.getMaxCount()) finishActivity(); refreshThumb(); } @@ -126,7 +126,7 @@ public void onRequestPermissionsResult(int requestCode, case 28: { if (grantResults.length > 0) { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - pickerController.displayImage(album.bucketId, fishton.isExceptGif); + pickerController.displayImage(album.bucketId, fishton.isExceptGif()); // permission was granted, yay! do the // calendar task you need to do. } else { @@ -158,29 +158,29 @@ public boolean onCreateOptionsMenu(Menu menu) { MenuItem menuDoneItem = menu.findItem(R.id.action_done); MenuItem menuAllDoneItem = menu.findItem(R.id.action_all_done); - if (fishton.drawableDoneButton != null) { - menuDoneItem.setIcon(fishton.drawableDoneButton); - } else if (fishton.strDoneMenu != null) { - if (fishton.colorTextMenu != Integer.MAX_VALUE) { - SpannableString spanString = new SpannableString(fishton.strDoneMenu); - spanString.setSpan(new ForegroundColorSpan(fishton.colorTextMenu), 0, spanString.length(), 0); //fi + if (fishton.getDrawableDoneButton() != null) { + menuDoneItem.setIcon(fishton.getDrawableDoneButton()); + } else if (fishton.getStrDoneMenu() != null) { + if (fishton.getColorTextMenu() != Integer.MAX_VALUE) { + SpannableString spanString = new SpannableString(fishton.getStrDoneMenu()); + spanString.setSpan(new ForegroundColorSpan(fishton.getColorTextMenu()), 0, spanString.length(), 0); //fi menuDoneItem.setTitle(spanString); } else { - menuDoneItem.setTitle(fishton.strDoneMenu); + menuDoneItem.setTitle(fishton.getStrDoneMenu()); } menuDoneItem.setIcon(null); } - if (fishton.isUseAllDoneButton) { + if (fishton.isUseAllDoneButton()){ menuAllDoneItem.setVisible(true); - if (fishton.drawableAllDoneButton != null) { - menuAllDoneItem.setIcon(fishton.drawableAllDoneButton); - } else if (fishton.strAllDoneMenu != null) { - if (fishton.colorTextMenu != Integer.MAX_VALUE) { - SpannableString spanString = new SpannableString(fishton.strAllDoneMenu); - spanString.setSpan(new ForegroundColorSpan(fishton.colorTextMenu), 0, spanString.length(), 0); //fi + if (fishton.getDrawableAllDoneButton() != null) { + menuAllDoneItem.setIcon(fishton.getDrawableAllDoneButton()); + } else if (fishton.getStrAllDoneMenu() != null) { + if (fishton.getColorTextMenu() != Integer.MAX_VALUE) { + SpannableString spanString = new SpannableString(fishton.getStrAllDoneMenu()); + spanString.setSpan(new ForegroundColorSpan(fishton.getColorTextMenu()), 0, spanString.length(), 0); //fi menuAllDoneItem.setTitle(spanString); } else { - menuAllDoneItem.setTitle(fishton.strAllDoneMenu); + menuAllDoneItem.setTitle(fishton.getStrAllDoneMenu()); } menuAllDoneItem.setIcon(null); } @@ -198,19 +198,19 @@ public boolean onOptionsItemSelected(MenuItem item) { // as you specify album parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_done) { - if (fishton.selectedImages.size() < fishton.minCount) { - Snackbar.make(recyclerView, fishton.messageNothingSelected, Snackbar.LENGTH_SHORT).show(); + if (fishton.getSelectedImages().size() < fishton.getMinCount()) { + Snackbar.make(recyclerView, fishton.getMessageNothingSelected(), Snackbar.LENGTH_SHORT).show(); } else { finishActivity(); } return true; - } else if (id == R.id.action_all_done) { - for (Uri pickerImage : fishton.pickerImages) { - if (fishton.selectedImages.size() == fishton.maxCount) { + } else if (id == R.id.action_all_done){ + for (Uri pickerImage : fishton.getPickerImages()) { + if (fishton.getSelectedImages().size() == fishton.getMaxCount()){ break; } - if (!fishton.selectedImages.contains(pickerImage)) { - fishton.selectedImages.add(pickerImage); + if (!fishton.getSelectedImages().contains(pickerImage)){ + fishton.getSelectedImages().add(pickerImage); } } finishActivity(); @@ -221,12 +221,12 @@ public boolean onOptionsItemSelected(MenuItem item) { public void showToolbarTitle(int total) { if (getSupportActionBar() != null) { - if (fishton.maxCount == 1 || !fishton.isShowCount) + if (fishton.getMaxCount() == 1 || !fishton.isShowCount()) getSupportActionBar() .setTitle(album.bucketName); else getSupportActionBar() - .setTitle(album.bucketName + " (" + total + "/" + fishton.maxCount + ")"); + .setTitle(album.bucketName + " (" + total + "/" + fishton.getMaxCount() + ")"); } } @@ -236,7 +236,7 @@ private void initController() { private void initView() { recyclerView = findViewById(R.id.recycler_picker_list); - layoutManager = new GridLayoutManager(this, fishton.photoSpanCount, RecyclerView.VERTICAL, false); + layoutManager = new GridLayoutManager(this, fishton.getPhotoSpanCount(), RecyclerView.VERTICAL, false); recyclerView.setLayoutManager(layoutManager); initToolBar(); } @@ -244,19 +244,19 @@ private void initView() { private void initToolBar() { Toolbar toolbar = findViewById(R.id.toolbar_picker_bar); setSupportActionBar(toolbar); - toolbar.setBackgroundColor(fishton.colorActionBar); - toolbar.setTitleTextColor(fishton.colorActionBarTitle); + toolbar.setBackgroundColor(fishton.getColorActionBar()); + toolbar.setTitleTextColor(fishton.getColorActionBarTitle()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - uiUtil.setStatusBarColor(this, fishton.colorStatusBar); + uiUtil.setStatusBarColor(this, fishton.getColorStatusBar()); } ActionBar bar = getSupportActionBar(); if (bar != null) { bar.setDisplayHomeAsUpEnabled(true); - if (fishton.drawableHomeAsUpIndicator != null) - getSupportActionBar().setHomeAsUpIndicator(fishton.drawableHomeAsUpIndicator); + if (fishton.getDrawableHomeAsUpIndicator() != null) + getSupportActionBar().setHomeAsUpIndicator(fishton.getDrawableHomeAsUpIndicator()); } - if (fishton.isStatusBarLight + if (fishton.isStatusBarLight() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { toolbar.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); } @@ -265,7 +265,7 @@ private void initToolBar() { public void setAdapter(Uri[] result) { - fishton.pickerImages = result; + fishton.setPickerImages(result); if (adapter == null) { adapter = new PickerGridAdapter(pickerController, pickerController.getPathDir(album.bucketId)); @@ -277,7 +277,7 @@ public void onDeselect() { }); } recyclerView.setAdapter(adapter); - showToolbarTitle(fishton.selectedImages.size()); + showToolbarTitle(fishton.getSelectedImages().size()); } private void refreshThumb() { @@ -291,7 +291,7 @@ private void refreshThumb() { ImageView imgThumbImage = item.findViewById(R.id.img_thumb_image); Uri image = (Uri) item.getTag(); if (image != null) { - int index = fishton.selectedImages.indexOf(image); + int index = fishton.getSelectedImages().indexOf(image); if (index != -1) { adapter.updateRadioButton(imgThumbImage, btnThumbCount, @@ -302,7 +302,7 @@ private void refreshThumb() { btnThumbCount, "", false); - showToolbarTitle(fishton.selectedImages.size()); + showToolbarTitle(fishton.getSelectedImages().size()); } } @@ -322,8 +322,8 @@ void transImageFinish(int position) { public void finishActivity() { Intent i = new Intent(); setResult(RESULT_OK, i); - if (fishton.isStartInAllView) - i.putParcelableArrayListExtra(Define.INTENT_PATH, fishton.selectedImages); + if (fishton.isStartInAllView()) + i.putParcelableArrayListExtra(Define.INTENT_PATH, fishton.getSelectedImages()); finish(); } diff --git a/FishBun/src/main/java/com/sangcomz/fishbun/util/ContextUtil.kt b/FishBun/src/main/java/com/sangcomz/fishbun/util/ContextUtil.kt new file mode 100644 index 00000000..94ebd14c --- /dev/null +++ b/FishBun/src/main/java/com/sangcomz/fishbun/util/ContextUtil.kt @@ -0,0 +1,6 @@ +package com.sangcomz.fishbun.util + +import android.content.Context +import androidx.annotation.DimenRes + +fun Context.getDimension(@DimenRes id: Int) = resources.getDimension(id).toInt() \ No newline at end of file diff --git a/FishBunDemo/src/main/java/com/sangcomz/fishbundemo/SubFragment.java b/FishBunDemo/src/main/java/com/sangcomz/fishbundemo/SubFragment.java index 669814ea..b57c1b82 100644 --- a/FishBunDemo/src/main/java/com/sangcomz/fishbundemo/SubFragment.java +++ b/FishBunDemo/src/main/java/com/sangcomz/fishbundemo/SubFragment.java @@ -15,6 +15,7 @@ import android.widget.ImageView; import com.sangcomz.fishbun.FishBun; +import com.sangcomz.fishbun.adapter.image.impl.PicassoAdapter; import com.sangcomz.fishbun.define.Define; import java.util.ArrayList; @@ -78,4 +79,4 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { } } } -} \ No newline at end of file +} diff --git a/FishBunDemo/src/main/java/com/sangcomz/fishbundemo/WithActivityActivity.java b/FishBunDemo/src/main/java/com/sangcomz/fishbundemo/WithActivityActivity.java index 85b8e781..da8dfb99 100644 --- a/FishBunDemo/src/main/java/com/sangcomz/fishbundemo/WithActivityActivity.java +++ b/FishBunDemo/src/main/java/com/sangcomz/fishbundemo/WithActivityActivity.java @@ -16,6 +16,7 @@ import com.sangcomz.fishbun.FishBun; import com.sangcomz.fishbun.adapter.image.impl.GlideAdapter; +import com.sangcomz.fishbun.adapter.image.impl.PicassoAdapter; import com.sangcomz.fishbun.define.Define; import java.util.ArrayList; @@ -142,4 +143,4 @@ public boolean onOptionsItemSelected(MenuItem item) { } return super.onOptionsItemSelected(item); } -} \ No newline at end of file +} diff --git a/FishBunDemo/src/main/java/com/sangcomz/fishbundemo/WithFragmentActivity.java b/FishBunDemo/src/main/java/com/sangcomz/fishbundemo/WithFragmentActivity.java index c04aa7f0..906c8c9e 100644 --- a/FishBunDemo/src/main/java/com/sangcomz/fishbundemo/WithFragmentActivity.java +++ b/FishBunDemo/src/main/java/com/sangcomz/fishbundemo/WithFragmentActivity.java @@ -1,6 +1,9 @@ package com.sangcomz.fishbundemo; +import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; import android.os.Bundle; import android.widget.RelativeLayout; @@ -19,4 +22,12 @@ protected void onCreate(Bundle savedInstanceState) { getSupportFragmentManager().beginTransaction().add(areaContainer.getId(), subFragment).commit(); } + + /** + * Send onActivityResult method to SubFragment + */ + @Override + protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + subFragment.onActivityResult(requestCode, resultCode, data); + } }