Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-client-android
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-client-android
Commits
6da421d3
Commit
6da421d3
authored
4 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
AccountFragment: load account using rx
Change-Id: Id2482a3d1ca91c7e46a4d4a728db4de357ea4acb
parent
236c24c7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ring-android/app/src/main/java/cx/ring/settings/AccountFragment.java
+30
-44
30 additions, 44 deletions
...d/app/src/main/java/cx/ring/settings/AccountFragment.java
with
30 additions
and
44 deletions
ring-android/app/src/main/java/cx/ring/settings/AccountFragment.java
+
30
−
44
View file @
6da421d3
...
...
@@ -20,15 +20,10 @@ package cx.ring.settings;
import
android.app.Activity
;
import
android.os.Bundle
;
import
android.text.TextUtils
;
import
android.view.LayoutInflater
;
import
android.view.Menu
;
import
android.view.MenuInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.ViewTreeObserver
;
import
android.widget.CompoundButton
;
import
android.widget.Toast
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
...
...
@@ -36,7 +31,6 @@ import androidx.appcompat.app.AlertDialog;
import
androidx.fragment.app.Fragment
;
import
com.google.android.material.dialog.MaterialAlertDialogBuilder
;
import
com.google.android.material.snackbar.Snackbar
;
import
javax.inject.Inject
;
...
...
@@ -45,20 +39,11 @@ import cx.ring.account.AccountEditionFragment;
import
cx.ring.account.JamiAccountSummaryFragment
;
import
cx.ring.application.JamiApplication
;
import
cx.ring.client.HomeActivity
;
import
cx.ring.daemon.Ringservice
;
import
cx.ring.databinding.FragAccountBinding
;
import
cx.ring.model.Account
;
import
cx.ring.model.Settings
;
import
cx.ring.mvp.BaseSupportFragment
;
import
cx.ring.mvp.GenericView
;
import
cx.ring.services.AccountService
;
import
io.reactivex.android.schedulers.AndroidSchedulers
;
import
io.reactivex.disposables.CompositeDisposable
;
import
static
cx
.
ring
.
daemon
.
Ringservice
.
getPluginsEnabled
;
import
static
cx
.
ring
.
daemon
.
Ringservice
.
setPluginsEnabled
;
/**
* TODO: improvements : handle multiples permissions for feature.
*/
public
class
AccountFragment
extends
Fragment
implements
ViewTreeObserver
.
OnScrollChangedListener
{
private
static
final
int
SCROLL_DIRECTION_UP
=
-
1
;
...
...
@@ -72,7 +57,7 @@ public class AccountFragment extends Fragment implements ViewTreeObserver.OnScro
}
private
FragAccountBinding
mBinding
;
private
Account
mAccount
;
private
final
CompositeDisposable
mDisposable
=
new
CompositeDisposable
()
;
@Inject
AccountService
mAccountService
;
...
...
@@ -89,38 +74,39 @@ public class AccountFragment extends Fragment implements ViewTreeObserver.OnScro
public
void
onDestroyView
()
{
super
.
onDestroyView
();
mBinding
=
null
;
mDisposable
.
clear
();
}
@Override
public
void
onViewCreated
(
@NonNull
View
view
,
Bundle
savedInstanceState
)
{
setHasOptionsMenu
(
true
);
super
.
onViewCreated
(
view
,
savedInstanceState
);
String
accountId
=
getArguments
().
getString
(
AccountEditionFragment
.
ACCOUNT_ID_KEY
);
mAccount
=
mAccountService
.
getAccount
(
accountId
);
mBinding
.
settingsChangePassword
.
setVisibility
(
mAccount
.
hasManager
()
?
View
.
GONE
:
View
.
VISIBLE
);
mBinding
.
settingsExport
.
setVisibility
(
mAccount
.
hasManager
()
?
View
.
GONE
:
View
.
VISIBLE
);
mBinding
.
systemChangePasswordTitle
.
setText
(
mAccount
.
hasPassword
()?
R
.
string
.
account_password_change
:
R
.
string
.
account_password_set
);
mBinding
.
scrollview
.
getViewTreeObserver
().
addOnScrollChangedListener
(
this
);
mBinding
.
settingsChangePassword
.
setOnClickListener
(
v
->
((
JamiAccountSummaryFragment
)
getParentFragment
()).
onPasswordChangeAsked
());
mBinding
.
settingsExport
.
setOnClickListener
(
v
->
((
JamiAccountSummaryFragment
)
getParentFragment
()).
onClickExport
());
mBinding
.
settingsDeleteAccount
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
AlertDialog
deleteDialog
=
createDeleteDialog
();
deleteDialog
.
show
();
}
});
mBinding
.
settingsBlackList
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
JamiAccountSummaryFragment
summaryFragment
=
((
JamiAccountSummaryFragment
)
AccountFragment
.
this
.
getParentFragment
());
if
(
summaryFragment
!=
null
)
{
summaryFragment
.
goToBlackList
(
accountId
);
}
}
});
String
accountId
=
getArguments
()
!=
null
?
getArguments
().
getString
(
AccountEditionFragment
.
ACCOUNT_ID_KEY
)
:
null
;
mDisposable
.
add
(
mAccountService
.
getAccountSingle
(
accountId
)
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
(
account
->
{
mBinding
.
settingsChangePassword
.
setVisibility
(
account
.
hasManager
()
?
View
.
GONE
:
View
.
VISIBLE
);
mBinding
.
settingsExport
.
setVisibility
(
account
.
hasManager
()
?
View
.
GONE
:
View
.
VISIBLE
);
mBinding
.
systemChangePasswordTitle
.
setText
(
account
.
hasPassword
()?
R
.
string
.
account_password_change
:
R
.
string
.
account_password_set
);
mBinding
.
settingsDeleteAccount
.
setOnClickListener
(
v
->
{
AlertDialog
deleteDialog
=
createDeleteDialog
(
account
.
getAccountID
());
deleteDialog
.
show
();
});
mBinding
.
settingsBlackList
.
setOnClickListener
(
v
->
{
JamiAccountSummaryFragment
summaryFragment
=
((
JamiAccountSummaryFragment
)
getParentFragment
());
if
(
summaryFragment
!=
null
)
{
summaryFragment
.
goToBlackList
(
account
.
getAccountID
());
}
});
},
e
->
{
JamiAccountSummaryFragment
summaryFragment
=
((
JamiAccountSummaryFragment
)
getParentFragment
());
if
(
summaryFragment
!=
null
)
{
summaryFragment
.
popBackStack
();
}
}));
}
@Override
...
...
@@ -133,11 +119,11 @@ public class AccountFragment extends Fragment implements ViewTreeObserver.OnScro
}
@NonNull
private
AlertDialog
createDeleteDialog
()
{
private
AlertDialog
createDeleteDialog
(
String
accountId
)
{
AlertDialog
alertDialog
=
new
MaterialAlertDialogBuilder
(
requireContext
())
.
setMessage
(
R
.
string
.
account_delete_dialog_message
)
.
setTitle
(
R
.
string
.
account_delete_dialog_title
)
.
setPositiveButton
(
R
.
string
.
menu_delete
,
(
dialog
,
whichButton
)
->
mAccountService
.
removeAccount
(
mAccount
.
getA
ccountI
D
()
))
.
setPositiveButton
(
R
.
string
.
menu_delete
,
(
dialog
,
whichButton
)
->
mAccountService
.
removeAccount
(
a
ccountI
d
))
.
setNegativeButton
(
android
.
R
.
string
.
cancel
,
null
)
.
create
();
Activity
activity
=
getActivity
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment