|
@ -1,6 +1,5 @@ |
|
|
package gr.thmmy.mthmmy.activities.main.recent; |
|
|
package gr.thmmy.mthmmy.activities.main.recent; |
|
|
|
|
|
|
|
|
import android.os.AsyncTask; |
|
|
|
|
|
import android.os.Bundle; |
|
|
import android.os.Bundle; |
|
|
import android.view.LayoutInflater; |
|
|
import android.view.LayoutInflater; |
|
|
import android.view.View; |
|
|
import android.view.View; |
|
@ -9,19 +8,17 @@ import android.widget.ProgressBar; |
|
|
import android.widget.RelativeLayout; |
|
|
import android.widget.RelativeLayout; |
|
|
import android.widget.Toast; |
|
|
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.DocumentReference; |
|
|
import com.google.firebase.firestore.DocumentSnapshot; |
|
|
import com.google.firebase.firestore.DocumentSnapshot; |
|
|
|
|
|
import com.google.firebase.firestore.FirebaseFirestore; |
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.List; |
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
|
import androidx.recyclerview.widget.DividerItemDecoration; |
|
|
import androidx.recyclerview.widget.DividerItemDecoration; |
|
|
import androidx.recyclerview.widget.LinearLayoutManager; |
|
|
import androidx.recyclerview.widget.LinearLayoutManager; |
|
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
|
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
|
|
import gr.thmmy.mthmmy.R; |
|
|
import gr.thmmy.mthmmy.R; |
|
|
import gr.thmmy.mthmmy.base.BaseApplication; |
|
|
|
|
|
import gr.thmmy.mthmmy.base.BaseFragment; |
|
|
import gr.thmmy.mthmmy.base.BaseFragment; |
|
|
import gr.thmmy.mthmmy.model.RecentItem; |
|
|
import gr.thmmy.mthmmy.model.RecentItem; |
|
|
import gr.thmmy.mthmmy.utils.CustomRecyclerView; |
|
|
import gr.thmmy.mthmmy.utils.CustomRecyclerView; |
|
@ -48,7 +45,8 @@ public class RecentFragment extends BaseFragment { |
|
|
private ArrayList<RecentItem> recentItems = new ArrayList<>(); |
|
|
private ArrayList<RecentItem> recentItems = new ArrayList<>(); |
|
|
|
|
|
|
|
|
// Required empty public constructor
|
|
|
// Required empty public constructor
|
|
|
public RecentFragment() {} |
|
|
public RecentFragment() { |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -74,45 +72,30 @@ public class RecentFragment extends BaseFragment { |
|
|
@Override |
|
|
@Override |
|
|
public void onActivityCreated(Bundle savedInstanceState) { |
|
|
public void onActivityCreated(Bundle savedInstanceState) { |
|
|
super.onActivityCreated(savedInstanceState); |
|
|
super.onActivityCreated(savedInstanceState); |
|
|
if (recentItems == null) { |
|
|
|
|
|
Timber.d("I'm ere"); |
|
|
|
|
|
new AsyncTask<Void, Void, Void>() { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
Timber.d("onActivityCreated"); |
|
|
protected Void doInBackground(Void... voids) { |
|
|
|
|
|
DocumentReference docRef = BaseApplication.getInstance().getFirestoredb() |
|
|
DocumentReference docRef = FirebaseFirestore.getInstance() |
|
|
.collection("recent_posts") |
|
|
.collection("recent_posts") |
|
|
.document("recent"); |
|
|
.document("recent"); |
|
|
Timber.d("I'm here"); |
|
|
Timber.i("I'm here"); |
|
|
docRef.get().addOnCompleteListener(task -> { |
|
|
docRef.get().addOnCompleteListener(task -> { |
|
|
Timber.d("I'm there"); |
|
|
Timber.i("I'm there"); |
|
|
progressBar.setVisibility(ProgressBar.INVISIBLE); |
|
|
progressBar.setVisibility(ProgressBar.INVISIBLE); |
|
|
if (task.isSuccessful()) { |
|
|
if (task.isSuccessful()) { |
|
|
DocumentSnapshot recentDocument = task.getResult(); |
|
|
DocumentSnapshot recentDocument = task.getResult(); |
|
|
List<DocumentReference> posts = (List<DocumentReference>) recentDocument.get("posts"); |
|
|
Timber.i("Type: " + recentDocument.get("posts").getClass().getName()); |
|
|
List<Task<DocumentSnapshot>> tasks = new ArrayList<>(); |
|
|
ArrayList<HashMap<String, Object>> posts = (ArrayList<HashMap<String, Object>>) recentDocument.get("posts"); |
|
|
for (DocumentReference documentReference : posts) { |
|
|
for (HashMap<String, Object> map : posts) { |
|
|
Task<DocumentSnapshot> documentSnapshotTask = documentReference.get(); |
|
|
RecentItem recentItem = new RecentItem(map); |
|
|
tasks.add(documentSnapshotTask); |
|
|
|
|
|
} |
|
|
|
|
|
Tasks.whenAllSuccess(tasks).addOnSuccessListener(objects -> { |
|
|
|
|
|
ArrayList<RecentItem> recentItems = new ArrayList<>(); |
|
|
|
|
|
for (Object object : objects) { |
|
|
|
|
|
RecentItem recentItem = ((DocumentSnapshot) object).toObject(RecentItem.class); |
|
|
|
|
|
recentItems.add(recentItem); |
|
|
recentItems.add(recentItem); |
|
|
} |
|
|
} |
|
|
}); |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
Toast.makeText(getContext(), "Network error", Toast.LENGTH_SHORT).show(); |
|
|
Toast.makeText(getContext(), "Network error", Toast.LENGTH_SHORT).show(); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
}.execute(); |
|
|
|
|
|
progressBar.setVisibility(ProgressBar.VISIBLE); |
|
|
progressBar.setVisibility(ProgressBar.VISIBLE); |
|
|
} |
|
|
} |
|
|
Timber.d("onActivityCreated"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|