Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjun committed Oct 22, 2017
1 parent 48530a4 commit d8daf13
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public interface CheckPointDao {

@Update int updateCheckPoint(CheckPoint checkPoint);

@Delete int deleteCheckPoint(CheckPoint checkPoint);
@Delete void deleteCheckPoint(CheckPoint checkPoint);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package in.arjsna.mapsalarm.db;

import io.reactivex.Completable;
import io.reactivex.Single;
import java.util.List;

Expand All @@ -18,8 +19,8 @@ public Single<Boolean> insertNewCheckPoint(CheckPoint checkPoint) {
return Single.fromCallable(() -> checkPointDao.insertNewCheckPoint(checkPoint) > 1);
}

public Single<Boolean> deleteCheckPoint(CheckPoint checkPoint) {
return Single.fromCallable(() -> checkPointDao.deleteCheckPoint(checkPoint) > 1);
public Completable deleteCheckPoint(CheckPoint checkPoint) {
return Completable.fromAction(() -> checkPointDao.deleteCheckPoint(checkPoint));
}

public Single<Integer> getCheckPointCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ static class CheckPointViewHolder extends RecyclerView.ViewHolder {
private final LocationAlarmMVPContract.ILocationPresenter<LocationAlarmMVPContract.ILocationAlarmView>
locationAlarmPresenter;
TextView checkPointName;
ImageView editBtn;
//ImageView editBtn;
ImageView deleteBtn;

CheckPointViewHolder(View itemView,
LocationAlarmMVPContract.ILocationPresenter<LocationAlarmMVPContract.ILocationAlarmView> locationAlarmPresenter) {
super(itemView);
this.locationAlarmPresenter = locationAlarmPresenter;
checkPointName = itemView.findViewById(R.id.check_point_name_tv);
editBtn = itemView.findViewById(R.id.edit_check_point_name);
//editBtn = itemView.findViewById(R.id.edit_check_point_name);
deleteBtn = itemView.findViewById(R.id.delete_check_point);
bindEvents();
}
Expand All @@ -62,8 +62,8 @@ private void bindEvents() {
v -> locationAlarmPresenter.onCheckPointItemClicked(getAdapterPosition()));
deleteBtn.setOnClickListener(
v -> locationAlarmPresenter.onDeleteCheckPoint(getAdapterPosition()));
editBtn.setOnClickListener(
v -> locationAlarmPresenter.onEditCheckPoint(getAdapterPosition()));
//editBtn.setOnClickListener(
// v -> locationAlarmPresenter.onEditCheckPoint(getAdapterPosition()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.jakewharton.rxbinding2.view.RxView;
import in.arjsna.mapsalarm.R;
Expand All @@ -39,6 +40,7 @@
import in.arjsna.mapsalarm.di.qualifiers.ActivityContext;
import in.arjsna.mapsalarm.global.PermissionUtils;
import in.arjsna.mapsalarm.mvpbase.BaseActivity;
import java.util.ArrayList;
import javax.inject.Inject;

public class LocationAlarmActivity extends BaseActivity
Expand All @@ -51,6 +53,7 @@ public class LocationAlarmActivity extends BaseActivity
private GoogleMap mMap;
private boolean mPermissionDenied = false;
private ImageView locationPin;
private ArrayList<Marker> mapMarker = new ArrayList<>();

@Inject
public CheckPointsAdapter checkPointsAdapter;
Expand Down Expand Up @@ -225,11 +228,11 @@ private void showMissingPermissionError() {

@Override
public void addMarkerOnMap(CheckPoint checkPoint) {
mMap.addMarker(new MarkerOptions()
mapMarker.add(mMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.flag))
.draggable(false)
.position(new LatLng(checkPoint.getLatitude(), checkPoint.getLongitude()))
.title(checkPoint.getName()));
.title(checkPoint.getName())));
}

@Override
Expand All @@ -244,4 +247,8 @@ public void showBottomSheet() {
@Override public void notifyListAdapter() {
checkPointsAdapter.notifyDataSetChanged();
}

@Override public void removeMarker(int adapterPosition) {
mapMarker.get(adapterPosition).remove();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ interface ILocationAlarmView extends IMVPView {
void showBottomSheet();

void notifyListAdapter();

void removeMarker(int adapterPosition);
}

interface ILocationPresenter<V extends ILocationAlarmView> extends IMVPPresenter<V> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import in.arjsna.mapsalarm.di.qualifiers.ActivityContext;
import in.arjsna.mapsalarm.global.LocationProvider;
import in.arjsna.mapsalarm.mvpbase.BasePresenter;
import io.reactivex.CompletableObserver;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.observers.DisposableSingleObserver;
import io.reactivex.schedulers.Schedulers;
Expand Down Expand Up @@ -101,7 +103,24 @@ private void addCheckPointMarkers() {
}

@Override public void onDeleteCheckPoint(int adapterPosition) {
// TODO: 20/10/17 delete
getCheckPointDataSource().deleteCheckPoint(allCheckPoints.get(adapterPosition))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new CompletableObserver() {
@Override public void onSubscribe(Disposable d) {

}

@Override public void onComplete() {
allCheckPoints.remove(adapterPosition);
getView().removeMarker(adapterPosition);
getView().notifyListAdapter();
}

@Override public void onError(Throwable e) {
getView().showError("Delete Failed");
}
});
}

@Override public void onEditCheckPoint(int adapterPosition) {
Expand Down
24 changes: 12 additions & 12 deletions app/src/main/res/layout/check_point_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@id/edit_check_point_name"
app:layout_constraintRight_toLeftOf="@id/delete_check_point"
android:padding="10dp"
android:textSize="16sp"
android:textStyle="bold"
android:text="adfadsf"
/>
<ImageView
android:id="@+id/edit_check_point_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_mode_edit"
app:layout_constraintLeft_toRightOf="@+id/check_point_name_tv"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@+id/delete_check_point"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"/>
<!--<ImageView-->
<!--android:id="@+id/edit_check_point_name"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:src="@drawable/ic_mode_edit"-->
<!--app:layout_constraintLeft_toRightOf="@+id/check_point_name_tv"-->
<!--app:layout_constraintTop_toTopOf="parent"-->
<!--app:layout_constraintBottom_toBottomOf="parent"-->
<!--app:layout_constraintRight_toLeftOf="@+id/delete_check_point"-->
<!--android:layout_marginRight="10dp"-->
<!--android:layout_marginEnd="10dp"/>-->
<ImageView
android:id="@+id/delete_check_point"
android:layout_width="wrap_content"
Expand Down

0 comments on commit d8daf13

Please sign in to comment.