From 87d2adba097cf484a053c075365387bf806e0261 Mon Sep 17 00:00:00 2001 From: Arjun Date: Thu, 19 Oct 2017 16:26:54 +0530 Subject: [PATCH] seperate activity created for alarm --- app/src/main/AndroidManifest.xml | 5 +- .../in/arjsna/mapsalarm/AlarmActivity.java | 19 ------ .../arjsna/mapsalarm/alarm/AlarmActivity.java | 62 +++++++++++++++++++ .../mapsalarm/alarm/AlarmMVPContract.java | 17 +++++ .../mapsalarm/alarm/AlarmPresenter.java | 25 ++++++++ .../bgservice/LocationAwareService.java | 4 +- .../di/components/ActivityComponent.java | 3 + .../mapsalarm/di/modules/ActivityModule.java | 10 ++- .../locationalarm/LocationAlarmActivity.java | 6 +- app/src/main/res/layout/activity_alarm.xml | 25 +++++--- 10 files changed, 142 insertions(+), 34 deletions(-) delete mode 100644 app/src/main/java/in/arjsna/mapsalarm/AlarmActivity.java create mode 100644 app/src/main/java/in/arjsna/mapsalarm/alarm/AlarmActivity.java create mode 100644 app/src/main/java/in/arjsna/mapsalarm/alarm/AlarmMVPContract.java create mode 100644 app/src/main/java/in/arjsna/mapsalarm/alarm/AlarmPresenter.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a351d99..12c5f3e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -3,8 +3,9 @@ package="in.arjsna.mapsalarm"> - + + diff --git a/app/src/main/java/in/arjsna/mapsalarm/AlarmActivity.java b/app/src/main/java/in/arjsna/mapsalarm/AlarmActivity.java deleted file mode 100644 index d505bb4..0000000 --- a/app/src/main/java/in/arjsna/mapsalarm/AlarmActivity.java +++ /dev/null @@ -1,19 +0,0 @@ -package in.arjsna.mapsalarm; - -import android.os.Bundle; -import android.support.design.widget.FloatingActionButton; -import android.support.design.widget.Snackbar; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import android.view.View; - -public class AlarmActivity extends AppCompatActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_alarm); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - setSupportActionBar(toolbar); - } -} diff --git a/app/src/main/java/in/arjsna/mapsalarm/alarm/AlarmActivity.java b/app/src/main/java/in/arjsna/mapsalarm/alarm/AlarmActivity.java new file mode 100644 index 0000000..c130888 --- /dev/null +++ b/app/src/main/java/in/arjsna/mapsalarm/alarm/AlarmActivity.java @@ -0,0 +1,62 @@ +package in.arjsna.mapsalarm.alarm; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.os.PowerManager; +import android.support.v7.widget.Toolbar; +import android.view.View; +import android.view.WindowManager; +import com.jakewharton.rxbinding2.view.RxView; +import in.arjsna.mapsalarm.R; +import in.arjsna.mapsalarm.bgservice.LocationAwareService; +import in.arjsna.mapsalarm.mvpbase.BaseActivity; +import javax.inject.Inject; + +public class AlarmActivity extends BaseActivity implements AlarmMVPContract.IAlarmView { + private PowerManager.WakeLock mWakeLock; + + @Inject + AlarmMVPContract.IAlarmPresenter alarmPresenter; + private View dismissButton; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); + mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | + PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "AlarmActivity"); + mWakeLock.acquire(); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); + + setContentView(R.layout.activity_alarm); + if (getActivityComponent() != null) { + getActivityComponent().inject(this); + alarmPresenter.onAttach(this); + } + initViews(); + bindEvents(); + } + + private void bindEvents() { + RxView.clicks(dismissButton) + .subscribe(__ -> alarmPresenter.onDismissButtonClicked()); + } + + private void initViews() { + dismissButton = findViewById(R.id.alarm_dismiss_view); + Toolbar toolbar = findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + alarmPresenter.onViewInitialised(); + } + + @Override public void stopService() { + Intent stopIntent = new Intent(AlarmActivity.this, LocationAwareService.class); + stopService(stopIntent); + } + + @Override protected void onDestroy() { + super.onDestroy(); + mWakeLock.release(); + } +} diff --git a/app/src/main/java/in/arjsna/mapsalarm/alarm/AlarmMVPContract.java b/app/src/main/java/in/arjsna/mapsalarm/alarm/AlarmMVPContract.java new file mode 100644 index 0000000..462682b --- /dev/null +++ b/app/src/main/java/in/arjsna/mapsalarm/alarm/AlarmMVPContract.java @@ -0,0 +1,17 @@ +package in.arjsna.mapsalarm.alarm; + +import in.arjsna.mapsalarm.mvpbase.IMVPPresenter; +import in.arjsna.mapsalarm.mvpbase.IMVPView; + +public interface AlarmMVPContract { + interface IAlarmView extends IMVPView { + + void stopService(); + } + + interface IAlarmPresenter extends IMVPPresenter { + void onViewInitialised(); + + void onDismissButtonClicked(); + } +} diff --git a/app/src/main/java/in/arjsna/mapsalarm/alarm/AlarmPresenter.java b/app/src/main/java/in/arjsna/mapsalarm/alarm/AlarmPresenter.java new file mode 100644 index 0000000..6ee9b2b --- /dev/null +++ b/app/src/main/java/in/arjsna/mapsalarm/alarm/AlarmPresenter.java @@ -0,0 +1,25 @@ +package in.arjsna.mapsalarm.alarm; + +import android.content.Context; +import in.arjsna.mapsalarm.db.CheckPointDataSource; +import in.arjsna.mapsalarm.di.qualifiers.ActivityContext; +import in.arjsna.mapsalarm.mvpbase.BasePresenter; +import javax.inject.Inject; + +public class AlarmPresenter extends BasePresenter + implements AlarmMVPContract.IAlarmPresenter { + + @Inject + public AlarmPresenter(@ActivityContext Context context, + CheckPointDataSource checkPointDataSource) { + super(context, checkPointDataSource); + } + + @Override public void onViewInitialised() { + + } + + @Override public void onDismissButtonClicked() { + getView().stopService(); + } +} diff --git a/app/src/main/java/in/arjsna/mapsalarm/bgservice/LocationAwareService.java b/app/src/main/java/in/arjsna/mapsalarm/bgservice/LocationAwareService.java index 92cc626..b6fab42 100644 --- a/app/src/main/java/in/arjsna/mapsalarm/bgservice/LocationAwareService.java +++ b/app/src/main/java/in/arjsna/mapsalarm/bgservice/LocationAwareService.java @@ -20,6 +20,7 @@ import com.google.android.gms.location.LocationCallback; import com.google.android.gms.location.LocationResult; import in.arjsna.mapsalarm.R; +import in.arjsna.mapsalarm.alarm.AlarmActivity; import in.arjsna.mapsalarm.db.CheckPoint; import in.arjsna.mapsalarm.db.CheckPointDataSource; import in.arjsna.mapsalarm.di.components.DaggerServiceComponent; @@ -191,9 +192,10 @@ private void startPlayer() { } private void openActivity() { - Intent myIntent = new Intent(getApplicationContext(), LocationAlarmActivity.class); + Intent myIntent = new Intent(getApplicationContext(), AlarmActivity.class); myIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); myIntent.setAction(LOCATION_REACHED); + System.out.println("Action Set"); startActivity(myIntent); } diff --git a/app/src/main/java/in/arjsna/mapsalarm/di/components/ActivityComponent.java b/app/src/main/java/in/arjsna/mapsalarm/di/components/ActivityComponent.java index 5b405f5..8323909 100644 --- a/app/src/main/java/in/arjsna/mapsalarm/di/components/ActivityComponent.java +++ b/app/src/main/java/in/arjsna/mapsalarm/di/components/ActivityComponent.java @@ -1,6 +1,7 @@ package in.arjsna.mapsalarm.di.components; import dagger.Component; +import in.arjsna.mapsalarm.alarm.AlarmActivity; import in.arjsna.mapsalarm.di.modules.ActivityModule; import in.arjsna.mapsalarm.di.scopes.ActivityScope; import in.arjsna.mapsalarm.locationalarm.LocationAlarmActivity; @@ -9,4 +10,6 @@ @Component (modules = ActivityModule.class, dependencies = ApplicationComponent.class) public interface ActivityComponent { void inject(LocationAlarmActivity locationAlarmActivity); + + void inject(AlarmActivity alarmActivity); } diff --git a/app/src/main/java/in/arjsna/mapsalarm/di/modules/ActivityModule.java b/app/src/main/java/in/arjsna/mapsalarm/di/modules/ActivityModule.java index 8e33f0f..1cb8c11 100644 --- a/app/src/main/java/in/arjsna/mapsalarm/di/modules/ActivityModule.java +++ b/app/src/main/java/in/arjsna/mapsalarm/di/modules/ActivityModule.java @@ -4,9 +4,10 @@ import android.support.v7.app.AppCompatActivity; import dagger.Module; import dagger.Provides; +import in.arjsna.mapsalarm.alarm.AlarmMVPContract; +import in.arjsna.mapsalarm.alarm.AlarmPresenter; import in.arjsna.mapsalarm.di.qualifiers.ActivityContext; import in.arjsna.mapsalarm.di.scopes.ActivityScope; -import in.arjsna.mapsalarm.global.LocationProvider; import in.arjsna.mapsalarm.locationalarm.LocationAlarmMVPContract; import in.arjsna.mapsalarm.locationalarm.LocationAlarmPresenter; @@ -30,4 +31,11 @@ LocationAlarmMVPContract.ILocationPresenter locationAlarmPresenter) { return locationAlarmPresenter; } + + @ActivityScope + @Provides + AlarmMVPContract.IAlarmPresenter provideAlarmPresenter( + AlarmPresenter alarmPresenter) { + return alarmPresenter; + } } diff --git a/app/src/main/java/in/arjsna/mapsalarm/locationalarm/LocationAlarmActivity.java b/app/src/main/java/in/arjsna/mapsalarm/locationalarm/LocationAlarmActivity.java index 8f75059..83ee22a 100644 --- a/app/src/main/java/in/arjsna/mapsalarm/locationalarm/LocationAlarmActivity.java +++ b/app/src/main/java/in/arjsna/mapsalarm/locationalarm/LocationAlarmActivity.java @@ -62,7 +62,6 @@ public class LocationAlarmActivity extends BaseActivity locationPresenter.onAttach(this); } initView(); - processIntent(); } private void processIntent() { @@ -73,6 +72,11 @@ private void processIntent() { } } + @Override protected void onResume() { + super.onResume(); + processIntent(); + } + private void initView() { //Toolbar toolbar = findViewById(R.id.toolbar); //setSupportActionBar(toolbar); diff --git a/app/src/main/res/layout/activity_alarm.xml b/app/src/main/res/layout/activity_alarm.xml index 41cea1e..1601253 100644 --- a/app/src/main/res/layout/activity_alarm.xml +++ b/app/src/main/res/layout/activity_alarm.xml @@ -1,15 +1,19 @@ - + tools:context="in.arjsna.mapsalarm.alarm.AlarmActivity"> - - - - + android:text="Dismiss" + app:layout_constraintTop_toBottomOf="@+id/app_bar_layout" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintBottom_toBottomOf="parent" + /> +