Skip to content

Commit

Permalink
First run setup dialog added and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkourlas committed Apr 23, 2015
1 parent 3d05f64 commit 473cfac
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 21 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.2.1 ##

* First run setup dialog added
* Bug fixes

## 0.2.0 ##

* Complete re-write
Expand Down
4 changes: 2 additions & 2 deletions VoIP.ms SMS/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ android {
applicationId "net.kourlas.voipms_sms"
minSdkVersion 21
targetSdkVersion 22
versionCode 101
versionName "0.2.0"
versionCode 102
versionName "0.2.1"
}

compileOptions {
Expand Down
11 changes: 4 additions & 7 deletions VoIP.ms SMS/src/main/java/net/kourlas/voipms_sms/Api.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* VoIP.ms SMS
* Copyright © 2015 Michael Kourlas
* Copyright 2015 Michael Kourlas
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
Expand Down Expand Up @@ -75,8 +75,7 @@ public void updateDid() {
} else if (preferences.getPassword().equals("")) {
Toast.makeText(context.getApplicationContext(), "Update DID: VoIP.ms API password not set",
Toast.LENGTH_SHORT).show();
}
if (isNetworkConnectionAvailable()) {
} else if (isNetworkConnectionAvailable()) {
try {
String voipUrl = "https://www.voip.ms/api/v1/rest.php?" + "&" +
"api_username=" + URLEncoder.encode(preferences.getEmail(), "UTF-8") + "&" +
Expand Down Expand Up @@ -167,8 +166,7 @@ public void deleteSms(long smsId) {
} else if (preferences.getPassword().equals("")) {
Toast.makeText(context.getApplicationContext(), "Delete SMS: VoIP.ms API password not set",
Toast.LENGTH_SHORT).show();
}
if (isNetworkConnectionAvailable()) {
} else if (isNetworkConnectionAvailable()) {
try {
String voipUrl = "https://www.voip.ms/api/v1/rest.php?" + "&" +
"api_username=" + URLEncoder.encode(preferences.getEmail(), "UTF-8") + "&" +
Expand Down Expand Up @@ -196,8 +194,7 @@ public void sendSms(String contact, String message) {
Toast.LENGTH_SHORT).show();
} else if (preferences.getDid().equals("")) {
Toast.makeText(context.getApplicationContext(), "Send SMS: DID not set", Toast.LENGTH_SHORT).show();
}
if (isNetworkConnectionAvailable()) {
} else if (isNetworkConnectionAvailable()) {
try {
String voipUrl = "https://www.voip.ms/api/v1/rest.php?" + "&" +
"api_username=" + URLEncoder.encode(preferences.getEmail(), "UTF-8") + "&" +
Expand Down
18 changes: 16 additions & 2 deletions VoIP.ms SMS/src/main/java/net/kourlas/voipms_sms/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@

public class Preferences {

private Context context;
private SharedPreferences sharedPreferences;

public Preferences(Context context) {
this.context = context;
if (context instanceof Activity) {
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(((Activity) context).getBaseContext());
} else {
Expand All @@ -44,7 +46,8 @@ public String getPassword() {
}

public int getDaysToSync() {
return Integer.parseInt(sharedPreferences.getString("sms_days_to_sync", ""));
return Integer.parseInt(sharedPreferences.getString("sms_days_to_sync", context.getResources().getString(
R.string.preferences_sms_days_to_sync_default_value)));
}

public String getDid() {
Expand All @@ -58,7 +61,18 @@ public void setDid(String did) {
}

public int getPollRate() {
return Integer.parseInt(sharedPreferences.getString("sms_poll_rate", ""));
return Integer.parseInt(sharedPreferences.getString("sms_poll_rate", context.getResources().getString(
R.string.preferences_sms_poll_rate_default_value)));
}

public boolean getFirstRun() {
return sharedPreferences.getBoolean("first_run", true);
}

public void setFirstRun(boolean firstRun) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("first_run", firstRun);
editor.apply();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

import android.app.Activity;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
Expand All @@ -30,10 +32,7 @@
import android.text.InputType;
import android.util.SparseBooleanArray;
import android.view.*;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SearchView;
import android.widget.*;
import com.example.android.floatingactionbuttonbasic.FloatingActionButton;
import net.kourlas.voipms_sms.Api;
import net.kourlas.voipms_sms.Preferences;
Expand All @@ -48,6 +47,7 @@ public class ConversationsActivity extends Activity {
private Api api;
private SmsDatabaseAdapter smsDatabaseAdapter;
private ConversationsListViewAdapter conversationsListViewAdapter;
private Preferences preferences;

@Override
public void onCreate(Bundle savedInstanceState) {
Expand All @@ -61,6 +61,9 @@ public void onCreate(Bundle savedInstanceState) {
smsDatabaseAdapter.open();
conversationsListViewAdapter = new ConversationsListViewAdapter(this);

preferences = new Preferences(this);
final Preferences preferences = this.preferences;

SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) findViewById(
R.id.swipe_refresh_layout);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
Expand Down Expand Up @@ -176,8 +179,19 @@ public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(conversationsActivity, NewConversationActivity.class);
startActivity(intent);
if (preferences.getEmail().equals("")) {
Toast.makeText(getApplicationContext(), "New Conversation: VoIP.ms portal email not set",
Toast.LENGTH_SHORT).show();
} else if (preferences.getPassword().equals("")) {
Toast.makeText(getApplicationContext(), "New Conversation: VoIP.ms API password not set",
Toast.LENGTH_SHORT).show();
} else if (preferences.getDid().equals("")) {
Toast.makeText(getApplicationContext(), "New Conversation: DID not set",
Toast.LENGTH_SHORT).show();
} else {
Intent intent = new Intent(conversationsActivity, NewConversationActivity.class);
startActivity(intent);
}
}
});

Expand All @@ -186,11 +200,31 @@ public void onClick(View v) {
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.cancel(pendingIntent);

Preferences preferences = new Preferences(this);
if (preferences.getPollRate() != 0) {
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() +
preferences.getPollRate() * 60 * 1000, preferences.getPollRate() * 60 * 1000, pendingIntent);
}

if (preferences.getFirstRun()) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Before using this app, make sure to set your VoIP.ms portal email address and API " +
"password in Settings.\n\nAfter setting your email and password, you will also need to pick an " +
"SMS-enabled DID by tapping the Select DID option in the menu at the upper right-hand corner of " +
"this screen.");
builder.setNegativeButton("Settings", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent preferencesIntent = new Intent(conversationsActivity, PreferencesActivity.class);
startActivity(preferencesIntent);
preferences.setFirstRun(false);
}
});
builder.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
preferences.setFirstRun(false);
}
});
builder.show();
}
}

public void onPause() {
Expand All @@ -202,7 +236,10 @@ public void onPause() {

public void onResume() {
conversationsListViewAdapter.refresh();
api.updateSmses();

if (!preferences.getFirstRun()) {
api.updateSmses();
}

getPackageManager().setComponentEnabledSetting(new ComponentName(this, RefreshReceiver.class),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
Expand Down
3 changes: 3 additions & 0 deletions VoIP.ms SMS/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<string name="preferences_reset">Clear SMS cache</string>
<string name="preferences_reset_summary">Delete local copy of SMS database</string>

<string name="preferences_sms_days_to_sync_default_value">7</string>
<string name="preferences_sms_poll_rate_default_value">15</string>

<string name="help_name">Help</string>

<string name="credits_name">Credits</string>
Expand Down
4 changes: 2 additions & 2 deletions VoIP.ms SMS/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

<PreferenceCategory android:title="@string/preferences_category_sms">
<ListPreference
android:defaultValue="7"
android:defaultValue="@string/preferences_sms_days_to_sync_default_value"
android:entries="@array/preferences_sms_days_to_sync_entries"
android:entryValues="@array/preferences_sms_days_to_sync_values"
android:key="sms_days_to_sync"
android:title="@string/preferences_sms_days_to_sync"/>
<ListPreference
android:defaultValue="15"
android:defaultValue="@string/preferences_sms_poll_rate_default_value"
android:entries="@array/preferences_sms_poll_rate_entries"
android:entryValues="@array/preferences_sms_poll_rate_values"
android:key="sms_poll_rate"
Expand Down

0 comments on commit 473cfac

Please sign in to comment.