Skip to content

Commit

Permalink
seperate activity created for alarm
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjun committed Oct 19, 2017
1 parent 3f122eb commit 87d2adb
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 34 deletions.
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
package="in.arjsna.mapsalarm">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE"/>

<application
android:name=".global.LocationAware"
android:allowBackup="true"
Expand Down Expand Up @@ -40,7 +41,7 @@
android:exported="false"/>

<activity
android:name=".AlarmActivity"
android:name=".alarm.AlarmActivity"
android:label="@string/title_activity_alarm">
</activity>
</application>
Expand Down
19 changes: 0 additions & 19 deletions app/src/main/java/in/arjsna/mapsalarm/AlarmActivity.java

This file was deleted.

62 changes: 62 additions & 0 deletions app/src/main/java/in/arjsna/mapsalarm/alarm/AlarmActivity.java
Original file line number Diff line number Diff line change
@@ -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<AlarmMVPContract.IAlarmView> 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();
}
}
17 changes: 17 additions & 0 deletions app/src/main/java/in/arjsna/mapsalarm/alarm/AlarmMVPContract.java
Original file line number Diff line number Diff line change
@@ -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<V extends IAlarmView> extends IMVPPresenter<V> {
void onViewInitialised();

void onDismissButtonClicked();
}
}
25 changes: 25 additions & 0 deletions app/src/main/java/in/arjsna/mapsalarm/alarm/AlarmPresenter.java
Original file line number Diff line number Diff line change
@@ -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<V extends AlarmMVPContract.IAlarmView> extends BasePresenter<V>
implements AlarmMVPContract.IAlarmPresenter<V> {

@Inject
public AlarmPresenter(@ActivityContext Context context,
CheckPointDataSource checkPointDataSource) {
super(context, checkPointDataSource);
}

@Override public void onViewInitialised() {

}

@Override public void onDismissButtonClicked() {
getView().stopService();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,4 +10,6 @@
@Component (modules = ActivityModule.class, dependencies = ApplicationComponent.class)
public interface ActivityComponent {
void inject(LocationAlarmActivity locationAlarmActivity);

void inject(AlarmActivity alarmActivity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -30,4 +31,11 @@ LocationAlarmMVPContract.ILocationPresenter<LocationAlarmMVPContract.ILocationAl
LocationAlarmPresenter<LocationAlarmMVPContract.ILocationAlarmView> locationAlarmPresenter) {
return locationAlarmPresenter;
}

@ActivityScope
@Provides
AlarmMVPContract.IAlarmPresenter<AlarmMVPContract.IAlarmView> provideAlarmPresenter(
AlarmPresenter<AlarmMVPContract.IAlarmView> alarmPresenter) {
return alarmPresenter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public class LocationAlarmActivity extends BaseActivity
locationPresenter.onAttach(this);
}
initView();
processIntent();
}

private void processIntent() {
Expand All @@ -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);
Expand Down
25 changes: 15 additions & 10 deletions app/src/main/res/layout/activity_alarm.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="in.arjsna.mapsalarm.AlarmActivity">
tools:context="in.arjsna.mapsalarm.alarm.AlarmActivity">

<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
Expand All @@ -20,13 +24,14 @@
app:popupTheme="@style/AppTheme.PopupOverlay"/>

</android.support.design.widget.AppBarLayout>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
<Button
android:id="@+id/alarm_dismiss_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email"/>

</android.support.design.widget.CoordinatorLayout>
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"
/>
</android.support.constraint.ConstraintLayout>

0 comments on commit 87d2adb

Please sign in to comment.