diff --git a/CHANGES.md b/CHANGES.md index dea6a76c..5332964d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +## 0.2.1 ## + +* First run setup dialog added +* Bug fixes + ## 0.2.0 ## * Complete re-write diff --git a/VoIP.ms SMS/build.gradle b/VoIP.ms SMS/build.gradle index c562eb57..a5879c55 100644 --- a/VoIP.ms SMS/build.gradle +++ b/VoIP.ms SMS/build.gradle @@ -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 { diff --git a/VoIP.ms SMS/src/main/java/net/kourlas/voipms_sms/Api.java b/VoIP.ms SMS/src/main/java/net/kourlas/voipms_sms/Api.java index 9df148e0..3e5324a8 100644 --- a/VoIP.ms SMS/src/main/java/net/kourlas/voipms_sms/Api.java +++ b/VoIP.ms SMS/src/main/java/net/kourlas/voipms_sms/Api.java @@ -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 @@ -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") + "&" + @@ -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") + "&" + @@ -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") + "&" + diff --git a/VoIP.ms SMS/src/main/java/net/kourlas/voipms_sms/Preferences.java b/VoIP.ms SMS/src/main/java/net/kourlas/voipms_sms/Preferences.java index a3492def..dce45033 100644 --- a/VoIP.ms SMS/src/main/java/net/kourlas/voipms_sms/Preferences.java +++ b/VoIP.ms SMS/src/main/java/net/kourlas/voipms_sms/Preferences.java @@ -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 { @@ -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() { @@ -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(); } } diff --git a/VoIP.ms SMS/src/main/java/net/kourlas/voipms_sms/activities/ConversationsActivity.java b/VoIP.ms SMS/src/main/java/net/kourlas/voipms_sms/activities/ConversationsActivity.java index 8e2f5f6d..ef7edf9f 100644 --- a/VoIP.ms SMS/src/main/java/net/kourlas/voipms_sms/activities/ConversationsActivity.java +++ b/VoIP.ms SMS/src/main/java/net/kourlas/voipms_sms/activities/ConversationsActivity.java @@ -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; @@ -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; @@ -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) { @@ -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() { @@ -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); + } } }); @@ -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() { @@ -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); diff --git a/VoIP.ms SMS/src/main/res/values/strings.xml b/VoIP.ms SMS/src/main/res/values/strings.xml index ca3989f3..048513be 100644 --- a/VoIP.ms SMS/src/main/res/values/strings.xml +++ b/VoIP.ms SMS/src/main/res/values/strings.xml @@ -35,6 +35,9 @@ Clear SMS cache Delete local copy of SMS database + 7 + 15 + Help Credits diff --git a/VoIP.ms SMS/src/main/res/xml/preferences.xml b/VoIP.ms SMS/src/main/res/xml/preferences.xml index dc5fa5c2..1eea807b 100644 --- a/VoIP.ms SMS/src/main/res/xml/preferences.xml +++ b/VoIP.ms SMS/src/main/res/xml/preferences.xml @@ -15,13 +15,13 @@