Commit 137a8cc3 authored by Dylan Jones's avatar Dylan Jones

Update to new rxJava and rxAndroid versions (still not fixing the bugs)

parent 26eddbac
Pipeline #4782 passed with stages
in 4 minutes and 21 seconds
......@@ -55,15 +55,15 @@ dependencies {
implementation 'io.realm:android-adapters:2.0.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.6.1'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.1'
//noinspection GradleCompatible
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'io.reactivex:rxandroid:1.2.1'
implementation 'io.reactivex:rxjava:1.3.8'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.12'
testImplementation 'junit:junit:4.12'
implementation 'com.jakewharton:butterknife:10.2.0'
kapt 'com.jakewharton:butterknife-compiler:10.2.0'
......@@ -75,5 +75,5 @@ dependencies {
implementation('com.crashlytics.sdk.android:crashlytics:2.6.6@aar') {
transitive = true
}
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.41"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
package srct.whatsopen.presenters;
import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import io.realm.Realm;
import io.realm.RealmList;
import io.realm.RealmResults;
import rx.Observable;
import io.reactivex.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import srct.whatsopen.model.Facility;
import srct.whatsopen.model.OpenTimes;
import srct.whatsopen.model.Schedule;
......@@ -35,6 +38,7 @@ public class MainPresenter {
private MainView mMainView;
private SharedPreferences pref;
private Realm mRealm;
private static final String TAG = "srct.whatsopen";
public void attachView(MainView view) {
mMainView = view;
......@@ -49,8 +53,9 @@ public class MainPresenter {
// Gets a Call from the given Retrofit service, then asynchronously executes it
// On success, copies the resulting facility list to the Realm DB
@SuppressLint("CheckResult")
public void loadFacilities() {
Log.d("srct.whatsopen", "loadFacilities: called");
Log.d(TAG, "loadFacilities: called");
if (mMainView != null)
mMainView.showProgressBar();
......@@ -62,36 +67,26 @@ public class MainPresenter {
.observeOn(AndroidSchedulers.mainThread())
.map(this::setStatus)
.subscribeOn(Schedulers.io())
.subscribe(new Subscriber<List<Facility>>() {
@Override
public void onCompleted() {
if (mMainView != null) {
mMainView.dismissProgressBar();
Log.d("srct.whatsopen", "onCompleted: called");
}
}
@Override
public void onError(Throwable e) {
updateOpenStatus();
if (mMainView != null) {
Log.i("srct.whatsopen", "MainPresenter.onError: printing stack trace!");
e.printStackTrace();
Toast.makeText(mMainView.getContext(), "Error getting data; " +
"schedules may be out of date.", Toast.LENGTH_LONG).show();
}
.doOnError(err -> {
updateOpenStatus();
if (mMainView != null) {
Log.i(TAG, "MainPresenter.onError: printing stack trace!");
err.printStackTrace();
Toast.makeText(mMainView.getContext(), "Error getting data; " +
"schedules may be out of date.", Toast.LENGTH_LONG).show();
}
@Override
public void onNext(List<Facility> facilities) {
writeToRealm(facilities);
})
.doOnComplete(() -> {
if (mMainView != null) {
mMainView.dismissProgressBar();
Log.d(TAG, "onCompleted: called");
}
});
}).subscribe(this::writeToRealm);
}
// Sets the favorite and open status of each Facility
private List<Facility> setStatus(List<Facility> facilities) {
Log.d("srct.whatsopen", "setStatus: called");
Log.d(TAG, "setStatus: called");
for (Facility facility : facilities) {
// Query SharedReferences for each Facility's favorite status. defaults to false
......
......@@ -2,9 +2,9 @@ package srct.whatsopen.util;
import java.util.List;
import io.reactivex.Observable;
import retrofit2.http.GET;
import rx.Observable;
import srct.whatsopen.model.Facility;
// Interface for Retrofit's Http request
......
......@@ -8,7 +8,7 @@ import com.google.gson.GsonBuilder;
import io.realm.RealmObject;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
/**
......@@ -57,7 +57,7 @@ public class WhatsOpenService {
.create();
sRetrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
}
......
......@@ -46,16 +46,25 @@ public class FacilityListAdapter extends
private Context mContext;
private Activity mActivity; // this is pretty much just for transition animations
private final String TAG = "srct.whatsopen";
// Mode describes the filtering for the elements to be displayed
public FacilityListAdapter(Context context, OrderedRealmCollection<Facility> data,
String mode, Realm realm, Activity activity) {
super(data, true);
Log.d(TAG, "FacilityListAdapter: new obj " + mode);
mContext = context;
mMode = mode;
mRealm = realm;
mActivity = activity;
Log.d(TAG, "FacilityListAdapter: size " + data.size());
for (Facility f : data ){
// Log.d(TAG, "FacilityListAdapter: " + f.getName());
}
// realm.asFlowable().subscribe((Realm r) -> { });
}
@Override
......@@ -186,7 +195,7 @@ public class FacilityListAdapter extends
.sort("isOpen", Sort.DESCENDING).findAll();
break;
}
Log.d("srct.whatsopen", "resetData: " + results);
Log.d(TAG, "resetData: " + results);
updateData(results);
}
......@@ -250,4 +259,12 @@ public class FacilityListAdapter extends
return mContext;
}
}
@Override
public int getItemCount() {
// TODO remove me - just for debug
int n = super.getItemCount();
Log.d("srct.whatsopen", "getItemCount: " + n + " " + mMode);
return n;
}
}
......@@ -80,13 +80,9 @@ public class FacilityListFragment extends Fragment implements MainView {
public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// mRecyclerView = ButterKnife.findById(view, R.id.rv_facilities);
mRecyclerView = view.findViewById(R.id.rv_facilities);
// mSwipeContainer = ButterKnife.findById(view, R.id.swipe_container);
mSwipeContainer = view.findViewById(R.id.swipe_container);
setUpRecyclerView(view);
Log.d("srct.whatsopen", "#################### we goin bois " + view);
Log.d("srct.whatsopen", "#################### we goin bois " + mRecyclerView);
mSwipeContainer.setOnRefreshListener(mPresenter::loadFacilities);
mSwipeContainer.setColorSchemeColors(getResources().getColor(R.color.colorPrimaryDark));
......@@ -128,7 +124,7 @@ public class FacilityListFragment extends Fragment implements MainView {
}
// Speeds things up for static lists
mRecyclerView.setHasFixedSize(true);
// mRecyclerView.setHasFixedSize(true);
// Adds dividers between items
Drawable dividerDrawable = ContextCompat.getDrawable(getActivity(), R.drawable.divider);
......
......@@ -31,7 +31,8 @@
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white" />
/>
<!-- android:background="@android:color/white" -->
</LinearLayout>
......
......@@ -4,8 +4,8 @@
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
tools:context="srct.whatsopen.views.fragments.FacilityListFragment">
<!-- android:background="#FFFFFF"-->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_facilities"
......
......@@ -21,9 +21,8 @@ android:orientation="horizontal">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Facility Name"
android:transitionName="facility_name"
android:textColor="#000000"
android:textSize="16sp" />
android:textSize="16sp"
android:transitionName="facility_name" />
<TextView
android:id="@+id/facility_duration"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment