Skip to content

Commit 2dbda3a

Browse files
committed
Created models, adapters and view models (#4441)
* created models, adapters and view models * Added Image Fragment * back button linked * Documentation and refractor * spaces * Butterknife annotation * DiffUtil * Added Examples * Extended Custom selector From Base Activity * made view model injectable
1 parent 63798c0 commit 2dbda3a

28 files changed

+1092
-73
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@
110110
<activity android:name=".quiz.QuizResultActivity"
111111
android:label="@string/result"/>
112112

113+
<activity android:name=".customselector.ui.selector.CustomSelectorActivity"
114+
android:label="CustomSelector"/>
115+
113116
<activity
114117
android:name=".category.CategoryDetailsActivity"
115118
android:label="@string/title_activity_featured_images"

app/src/main/java/fr/free/nrw/commons/contributions/ContributionsListFragment.java

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static fr.free.nrw.commons.di.NetworkingModule.NAMED_LANGUAGE_WIKI_PEDIA_WIKI_SITE;
66

77
import android.content.Context;
8+
import android.content.Intent;
89
import android.content.res.Configuration;
910
import android.net.Uri;
1011
import android.os.Bundle;
@@ -29,13 +30,16 @@
2930
import androidx.recyclerview.widget.SimpleItemAnimator;
3031
import butterknife.BindView;
3132
import butterknife.ButterKnife;
33+
import butterknife.OnClick;
3234
import com.google.android.material.floatingactionbutton.FloatingActionButton;
3335
import fr.free.nrw.commons.Media;
3436
import fr.free.nrw.commons.R;
3537
import fr.free.nrw.commons.Utils;
38+
import fr.free.nrw.commons.customselector.ui.selector.CustomSelectorActivity;
3639
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
3740
import fr.free.nrw.commons.utils.DialogUtil;
3841
import fr.free.nrw.commons.media.MediaClient;
42+
import fr.free.nrw.commons.utils.SystemThemeUtils;
3943
import fr.free.nrw.commons.utils.ViewUtil;
4044
import java.util.Locale;
4145
import javax.inject.Inject;
@@ -53,20 +57,25 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
5357

5458
private static final String RV_STATE = "rv_scroll_state";
5559

56-
@BindView(R.id.contributionsList)
57-
RecyclerView rvContributionsList;
58-
@BindView(R.id.loadingContributionsProgressBar)
59-
ProgressBar progressBar;
60-
@BindView(R.id.fab_plus)
61-
FloatingActionButton fabPlus;
62-
@BindView(R.id.fab_camera)
63-
FloatingActionButton fabCamera;
64-
@BindView(R.id.fab_gallery)
65-
FloatingActionButton fabGallery;
66-
@BindView(R.id.noContributionsYet)
67-
TextView noContributionsYet;
68-
@BindView(R.id.fab_layout)
69-
LinearLayout fab_layout;
60+
@BindView(R.id.contributionsList)
61+
RecyclerView rvContributionsList;
62+
@BindView(R.id.loadingContributionsProgressBar)
63+
ProgressBar progressBar;
64+
@BindView(R.id.fab_plus)
65+
FloatingActionButton fabPlus;
66+
@BindView(R.id.fab_camera)
67+
FloatingActionButton fabCamera;
68+
@BindView(R.id.fab_gallery)
69+
FloatingActionButton fabGallery;
70+
@BindView(R.id.noContributionsYet)
71+
TextView noContributionsYet;
72+
@BindView(R.id.fab_layout)
73+
LinearLayout fab_layout;
74+
@BindView(R.id.fab_custom_gallery)
75+
FloatingActionButton fabCustomGallery;
76+
77+
@Inject
78+
SystemThemeUtils systemThemeUtils;
7079

7180
@Inject
7281
ContributionController controller;
@@ -260,25 +269,35 @@ private void setListeners() {
260269
});
261270
}
262271

263-
private void animateFAB(final boolean isFabOpen) {
264-
this.isFabOpen = !isFabOpen;
265-
if (fabPlus.isShown()) {
266-
if (isFabOpen) {
267-
fabPlus.startAnimation(rotate_backward);
268-
fabCamera.startAnimation(fab_close);
269-
fabGallery.startAnimation(fab_close);
270-
fabCamera.hide();
271-
fabGallery.hide();
272-
} else {
273-
fabPlus.startAnimation(rotate_forward);
274-
fabCamera.startAnimation(fab_open);
275-
fabGallery.startAnimation(fab_open);
276-
fabCamera.show();
277-
fabGallery.show();
278-
}
279-
this.isFabOpen = !isFabOpen;
280-
}
272+
@OnClick(R.id.fab_custom_gallery)
273+
void launchCustomSelector(){
274+
Intent intent = new Intent(getActivity(), CustomSelectorActivity.class);
275+
startActivity(intent);
276+
}
277+
278+
private void animateFAB(final boolean isFabOpen) {
279+
this.isFabOpen = !isFabOpen;
280+
if (fabPlus.isShown()) {
281+
if (isFabOpen) {
282+
fabPlus.startAnimation(rotate_backward);
283+
fabCamera.startAnimation(fab_close);
284+
fabGallery.startAnimation(fab_close);
285+
fabCustomGallery.startAnimation(fab_close);
286+
fabCamera.hide();
287+
fabGallery.hide();
288+
fabCustomGallery.hide();
289+
} else {
290+
fabPlus.startAnimation(rotate_forward);
291+
fabCamera.startAnimation(fab_open);
292+
fabGallery.startAnimation(fab_open);
293+
fabCustomGallery.startAnimation(fab_open);
294+
fabCamera.show();
295+
fabGallery.show();
296+
fabCustomGallery.show();
297+
}
298+
this.isFabOpen = !isFabOpen;
281299
}
300+
}
282301

283302
/**
284303
* Shows welcome message if user has no contributions yet i.e. new user.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package fr.free.nrw.commons.customselector.listeners
2+
3+
import fr.free.nrw.commons.customselector.model.Folder
4+
5+
interface FolderClickListener {
6+
fun onFolderClick(folder : Folder)
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package fr.free.nrw.commons.customselector.listeners
2+
3+
import fr.free.nrw.commons.customselector.model.Image
4+
5+
interface ImageLoaderListener {
6+
fun onImageLoaded(images: ArrayList<Image>)
7+
fun onFailed(throwable: Throwable)
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package fr.free.nrw.commons.customselector.listeners
2+
3+
import fr.free.nrw.commons.customselector.model.Image
4+
5+
interface ImageSelectListener {
6+
fun onSelectedImagesChanged(selectedImages: ArrayList<Image>)
7+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package fr.free.nrw.commons.customselector.model
2+
3+
sealed class CallbackStatus {
4+
/**
5+
IDLE : The callback is idle , doing nothing.
6+
*/
7+
object IDLE : CallbackStatus()
8+
9+
/**
10+
FETCHING : Fetching images.
11+
*/
12+
object FETCHING : CallbackStatus()
13+
14+
/**
15+
SUCCESS : Success fetching images.
16+
*/
17+
object SUCCESS : CallbackStatus()
18+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package fr.free.nrw.commons.customselector.model
2+
3+
data class Folder(
4+
/**
5+
bucketId : Unique directory id, eg 540528482
6+
*/
7+
var bucketId: Long,
8+
9+
/**
10+
name : bucket/folder name, eg Camera
11+
*/
12+
var name: String,
13+
14+
/**
15+
images : folder images, list of all images under this folder.
16+
*/
17+
var images: ArrayList<Image> = arrayListOf<Image>()
18+
19+
20+
) {
21+
/**
22+
* Indicates whether some other object is "equal to" this one.
23+
*/
24+
override fun equals(other: Any?): Boolean {
25+
26+
if (javaClass != other?.javaClass) {
27+
return false
28+
}
29+
30+
other as Folder
31+
32+
if (bucketId != other.bucketId) {
33+
return false
34+
}
35+
if (name != other.name) {
36+
return false
37+
}
38+
if (images != other.images) {
39+
return false
40+
}
41+
42+
return true
43+
}
44+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
package fr.free.nrw.commons.customselector.model
2+
3+
import android.net.Uri
4+
import android.os.Parcel
5+
import android.os.Parcelable
6+
7+
data class Image(
8+
/**
9+
id : Unique image id, primary key of image in device, eg 104950
10+
*/
11+
var id: Long,
12+
13+
/**
14+
name : Name of the image with extension, eg CommonsLogo.jpeg
15+
*/
16+
var name: String,
17+
18+
/**
19+
uri : Uri of the image, points to image location or name, eg content://media/external/images/camera/10495 (Android 10)
20+
*/
21+
var uri: Uri,
22+
23+
/**
24+
path : System path of the image, eg storage/emulated/0/camera/CommonsLogo.jpeg
25+
*/
26+
var path: String,
27+
28+
/**
29+
bucketId : bucketId of folder, eg 540528482
30+
*/
31+
var bucketId: Long = 0,
32+
33+
/**
34+
bucketName : name of folder, eg Camera
35+
*/
36+
var bucketName: String = "",
37+
38+
/**
39+
sha1 : sha1 of original image.
40+
*/
41+
var sha1: String = ""
42+
) : Parcelable {
43+
44+
/**
45+
default parcelable constructor.
46+
*/
47+
constructor(parcel: Parcel):
48+
this(parcel.readLong(),
49+
parcel.readString()!!,
50+
parcel.readParcelable(Uri::class.java.classLoader)!!,
51+
parcel.readString()!!,
52+
parcel.readLong(),
53+
parcel.readString()!!,
54+
parcel.readString()!!
55+
)
56+
57+
/**
58+
Write to parcel method.
59+
*/
60+
override fun writeToParcel(parcel: Parcel, flags: Int) {
61+
parcel.writeLong(id)
62+
parcel.writeString(name)
63+
parcel.writeParcelable(uri, flags)
64+
parcel.writeString(path)
65+
parcel.writeLong(bucketId)
66+
parcel.writeString(bucketName)
67+
parcel.writeString(sha1)
68+
}
69+
70+
/**
71+
* Describe the kinds of special objects contained in this Parcelable
72+
*/
73+
override fun describeContents(): Int {
74+
return 0
75+
}
76+
77+
/**
78+
* Indicates whether some other object is "equal to" this one.
79+
*/
80+
override fun equals(other: Any?): Boolean {
81+
82+
if(javaClass != other?.javaClass) {
83+
return false
84+
}
85+
86+
other as Image
87+
88+
if(id != other.id) {
89+
return false;
90+
}
91+
if(name != other.name) {
92+
return false;
93+
}
94+
if(uri != other.uri) {
95+
return false;
96+
}
97+
if(path != other.path) {
98+
return false;
99+
}
100+
if(bucketId != other.bucketId) {
101+
return false;
102+
}
103+
if(bucketName != other.bucketName) {
104+
return false;
105+
}
106+
if(sha1 != other.sha1) {
107+
return false;
108+
}
109+
110+
return true
111+
}
112+
113+
/**
114+
* Parcelable companion object
115+
*/
116+
companion object CREATOR : Parcelable.Creator<Image> {
117+
override fun createFromParcel(parcel: Parcel): Image {
118+
return Image(parcel)
119+
}
120+
121+
override fun newArray(size: Int): Array<Image?> {
122+
return arrayOfNulls(size)
123+
}
124+
}
125+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package fr.free.nrw.commons.customselector.model
2+
3+
data class Result(
4+
/**
5+
* CallbackStatus : stores the result status
6+
*/
7+
val status:CallbackStatus,
8+
9+
/**
10+
* Images : images retrieved
11+
*/
12+
val images: ArrayList<Image>) {
13+
}

0 commit comments

Comments
 (0)