Skip to content

Commit

Permalink
Merge pull request #133 from yashk2000/logout
Browse files Browse the repository at this point in the history
Fix #132 Add option to logout
  • Loading branch information
yashk2000 committed Jun 23, 2020
2 parents e5281ae + 78ef613 commit 439932d
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 5 deletions.
Expand Up @@ -17,6 +17,7 @@ import javax.inject.Singleton
@Singleton
class PreferencesHelper @Inject constructor(@ApplicationContext context: Context?) {
private val sharedPreferences: SharedPreferences

fun clear() {
val editor = sharedPreferences.edit()
//prevent deletion of url and tenant
Expand Down
Expand Up @@ -29,10 +29,13 @@ import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread
import org.mifos.visionppi.R
import org.mifos.visionppi.adapters.ClientSearchAdapter
import org.mifos.visionppi.api.local.PreferencesHelper
import org.mifos.visionppi.databinding.ActivityMainBinding
import org.mifos.visionppi.objects.Client
import org.mifos.visionppi.ui.activities.LoginActivity
import org.mifos.visionppi.ui.client_profile.ClientProfileActivity
import org.mifos.visionppi.ui.user_profile.UserProfileActivity
import org.mifos.visionppi.utils.PrefManager


/**
Expand Down Expand Up @@ -178,6 +181,14 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
sendIntent.type = "text/plain"
startActivity(sendIntent)
}
R.id.logout -> {
val preferencesHelper = PreferencesHelper(baseContext)
preferencesHelper.clear()
val prefManager = PrefManager()
prefManager.clear(this, baseContext)
val intent = Intent(applicationContext, LoginActivity::class.java)
startActivity(intent)
}
}

drawer_layout.closeDrawer(GravityCompat.START)
Expand Down
Expand Up @@ -4,6 +4,7 @@ import android.app.Activity
import android.content.Context
import com.google.gson.Gson
import org.mifos.visionppi.R
import org.mifos.visionppi.api.local.PreferencesHelper
import org.mifos.visionppi.models.User

/**
Expand Down Expand Up @@ -38,4 +39,15 @@ class PrefManager {
putString(USERNAME, username, activity, context)
putString(PASSWORD, password, activity, context)
}

fun clear(activity:Activity, context: Context) {
val sharedPref = activity.getSharedPreferences(context.getString(R.string.pref_file_name),Context.MODE_PRIVATE)

val editor = sharedPref.edit()
//prevent deletion of url and tenant
for ((key) in sharedPref.all) {
editor.remove(key)
}
editor.apply()
}
}
11 changes: 11 additions & 0 deletions visionppi/app/src/main/res/drawable-anydpi/ic_logout.xml
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#333333"
android:alpha="0.6">
<path
android:fillColor="@android:color/white"
android:pathData="M10.09,15.59L11.5,17l5,-5 -5,-5 -1.41,1.41L12.67,11H3v2h9.67l-2.58,2.59zM19,3H5c-1.11,0 -2,0.9 -2,2v4h2V5h14v14H5v-4H3v4c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2V5c0,-1.1 -0.9,-2 -2,-2z"/>
</vector>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions visionppi/app/src/main/res/menu/activity_main_drawer.xml
Expand Up @@ -18,6 +18,11 @@
android:icon="@drawable/ic_share"
android:title="@string/share"/>

<item
android:id="@+id/logout"
android:icon="@drawable/ic_logout"
android:title="@string/logout"/>

</group>

</menu>
6 changes: 1 addition & 5 deletions visionppi/app/src/main/res/values/strings.xml
Expand Up @@ -8,8 +8,6 @@
<string name="cancel">Cancel</string>
<string name="create_an_account">Create an account</string>

x

<string name="error_validation_blank">%1$s cannot be blank</string>
<string name="error_validation_minimum_chars">%1$s cannot be less than %2$d characters</string>
<string name="error_validation_cannot_contain_spaces">%1$s cannot contain %2$s</string>
Expand All @@ -23,8 +21,7 @@
<string name="enter_passcode">Enter 4 digit Passcode</string>
<string name="error_passcode">Passcode should be of 4 digit</string>
<string name="incorrect_passcode">Incorrect Passcode</string>
<string name="incorrect_passcode_more_than_three">You have entered incorrect Passcode more than
3 times
<string name="incorrect_passcode_more_than_three">You have entered incorrect Passcode more than 3 times
</string>
<string name="skip">Skip</string>
<string name="save">Save</string>
Expand Down Expand Up @@ -126,5 +123,4 @@
<string name="search_query">Enter name/account number of client</string>
<string name="search_results">Client Results</string>


</resources>

0 comments on commit 439932d

Please sign in to comment.