diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java index 86691365..0e0594ef 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java @@ -1,6 +1,5 @@ package gr.thmmy.mthmmy.activities.main.recent; -import android.os.AsyncTask; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -9,19 +8,17 @@ import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.Toast; -import com.google.android.gms.tasks.Task; -import com.google.android.gms.tasks.Tasks; import com.google.firebase.firestore.DocumentReference; import com.google.firebase.firestore.DocumentSnapshot; +import com.google.firebase.firestore.FirebaseFirestore; import java.util.ArrayList; -import java.util.List; +import java.util.HashMap; import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import gr.thmmy.mthmmy.R; -import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.model.RecentItem; import gr.thmmy.mthmmy.utils.CustomRecyclerView; @@ -48,7 +45,8 @@ public class RecentFragment extends BaseFragment { private ArrayList recentItems = new ArrayList<>(); // Required empty public constructor - public RecentFragment() {} + public RecentFragment() { + } /** @@ -74,44 +72,29 @@ public class RecentFragment extends BaseFragment { @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - if (recentItems == null) { - Timber.d("I'm ere"); - new AsyncTask() { - - @Override - protected Void doInBackground(Void... voids) { - DocumentReference docRef = BaseApplication.getInstance().getFirestoredb() - .collection("recent_posts") - .document("recent"); - Timber.d("I'm here"); - docRef.get().addOnCompleteListener(task -> { - Timber.d("I'm there"); - progressBar.setVisibility(ProgressBar.INVISIBLE); - if (task.isSuccessful()) { - DocumentSnapshot recentDocument = task.getResult(); - List posts = (List) recentDocument.get("posts"); - List> tasks = new ArrayList<>(); - for (DocumentReference documentReference : posts) { - Task documentSnapshotTask = documentReference.get(); - tasks.add(documentSnapshotTask); - } - Tasks.whenAllSuccess(tasks).addOnSuccessListener(objects -> { - ArrayList recentItems = new ArrayList<>(); - for (Object object : objects) { - RecentItem recentItem = ((DocumentSnapshot) object).toObject(RecentItem.class); - recentItems.add(recentItem); - } - }); - } else { - Toast.makeText(getContext(), "Network error", Toast.LENGTH_SHORT).show(); - } - }); - return null; - } - }.execute(); - progressBar.setVisibility(ProgressBar.VISIBLE); - } + Timber.d("onActivityCreated"); + + DocumentReference docRef = FirebaseFirestore.getInstance() + .collection("recent_posts") + .document("recent"); + Timber.i("I'm here"); + docRef.get().addOnCompleteListener(task -> { + Timber.i("I'm there"); + progressBar.setVisibility(ProgressBar.INVISIBLE); + if (task.isSuccessful()) { + DocumentSnapshot recentDocument = task.getResult(); + Timber.i("Type: " + recentDocument.get("posts").getClass().getName()); + ArrayList> posts = (ArrayList>) recentDocument.get("posts"); + for (HashMap map : posts) { + RecentItem recentItem = new RecentItem(map); + recentItems.add(recentItem); + } + } else { + Toast.makeText(getContext(), "Network error", Toast.LENGTH_SHORT).show(); + } + }); + progressBar.setVisibility(ProgressBar.VISIBLE); } diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java index 7730fed9..55b1a9be 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java @@ -53,7 +53,6 @@ public class BaseApplication extends Application { //Firebase Analytics private FirebaseAnalytics firebaseAnalytics; - private FirebaseFirestore firestoredb; //Client & SessionManager private OkHttpClient client; @@ -95,7 +94,6 @@ public class BaseApplication extends Application { Timber.i("Starting app with Analytics enabled."); else Timber.i("Starting app with Analytics disabled."); - firestoredb = FirebaseFirestore.getInstance(); SharedPrefsCookiePersistor sharedPrefsCookiePersistor = new SharedPrefsCookiePersistor(getApplicationContext()); PersistentCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), sharedPrefsCookiePersistor); @@ -184,10 +182,6 @@ public class BaseApplication extends Application { return client; } - public FirebaseFirestore getFirestoredb() { - return firestoredb; - } - public SessionManager getSessionManager() { return sessionManager; } diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/RecentItem.java b/app/src/main/java/gr/thmmy/mthmmy/model/RecentItem.java index d03c17d2..4baf0b42 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/RecentItem.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/RecentItem.java @@ -1,6 +1,7 @@ package gr.thmmy.mthmmy.model; import java.util.Date; +import java.util.HashMap; public class RecentItem { private int boardId, postId, topicId, posterId; @@ -19,6 +20,10 @@ public class RecentItem { this.timestamp = new Date(timestamp); } + public RecentItem(HashMap keymap) { + + } + public Date getTimestamp() { return timestamp; } diff --git a/build.gradle b/build.gradle index be2e6a2a..278b54aa 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.3.1' + classpath 'com.android.tools.build:gradle:3.3.2' classpath 'com.google.gms:google-services:4.2.0' classpath 'io.fabric.tools:gradle:1.26.1' classpath 'org.ajoberstar.grgit:grgit-core:3.0.0' // Also change in app/gradle/grgit.gradle