Skip to content
Snippets Groups Projects
Commit c37e8bee authored by John Carlson's avatar John Carlson
Browse files

Dialogs, other things to Kotlin

parent 0219ec79
No related branches found
No related tags found
No related merge requests found
Showing
with 373 additions and 418 deletions
Loading
Loading
@@ -38,7 +38,7 @@ class ActivityActivity : BaseActivity() {
 
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
App.get().prefs.startingView = Prefs.STARTING_VIEW_ACTIVITY
App.get().prefs.setStartingView(Prefs.STARTING_VIEW_ACTIVITY)
setContentView(R.layout.activity_activity)
ButterKnife.bind(this)
 
Loading
Loading
Loading
Loading
@@ -121,12 +121,14 @@ class AddUserActivity : MorphActivity() {
teleprinter = Teleprinter(this)
projectId = intent.getLongExtra(KEY_PROJECT_ID, -1)
group = Parcels.unwrap<Group>(intent.getParcelableExtra<Parcelable>(KEY_GROUP))
dialogAccess = AccessDialog(this, AccessDialog.Listener { accessLevel ->
dialogAccess.showLoading()
if (group == null) {
add(App.get().gitLab.addProjectMember(projectId, selectedUser!!.id, accessLevel))
} else {
add(App.get().gitLab.addGroupMember(projectId, selectedUser!!.id, accessLevel))
dialogAccess = AccessDialog(this, object : AccessDialog.Listener {
override fun onAccessApplied(accessLevel: Int) {
dialogAccess.showLoading()
if (group == null) {
add(App.get().gitLab.addProjectMember(projectId, selectedUser!!.id, accessLevel))
} else {
add(App.get().gitLab.addGroupMember(projectId, selectedUser!!.id, accessLevel))
}
}
})
toolbar.setNavigationIcon(R.drawable.ic_back_24dp)
Loading
Loading
Loading
Loading
@@ -75,7 +75,7 @@ class GroupsActivity : BaseActivity() {
 
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
App.get().prefs.startingView = Prefs.STARTING_VIEW_GROUPS
App.get().prefs.setStartingView(Prefs.STARTING_VIEW_GROUPS)
setContentView(R.layout.activity_groups)
ButterKnife.bind(this)
App.bus().register(this)
Loading
Loading
Loading
Loading
@@ -55,7 +55,7 @@ class LaunchActivity : BaseActivity() {
if (accounts.isEmpty()) {
Navigator.navigateToLogin(this)
finish()
} else if (App.get().prefs.isRequireDeviceAuth) {
} else if (App.get().prefs.isRequiredDeviceAuth()) {
showKeyguard()
} else {
if (PRIVATE_KEY_ENABLED) {
Loading
Loading
Loading
Loading
@@ -489,7 +489,7 @@ class LoginActivity : BaseActivity() {
}
 
fun isAlreadySignedIn(url: String, usernameOrEmailOrPrivateToken: String): Boolean {
val accounts = App.get().prefs.accounts
val accounts = App.get().prefs.getAccounts()
for (account in accounts) {
if (account.serverUrl == Uri.parse(url)) {
if (usernameOrEmailOrPrivateToken == account.user.username
Loading
Loading
Loading
Loading
@@ -122,7 +122,7 @@ class ProjectActivity : BaseActivity() {
 
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
App.get().prefs.startingView = Prefs.STARTING_VIEW_PROJECTS
App.get().prefs.setStartingView(Prefs.STARTING_VIEW_PROJECTS)
setContentView(R.layout.activity_project)
ButterKnife.bind(this)
var project: Project? = Parcels.unwrap<Project>(intent.getParcelableExtra<Parcelable>(EXTRA_PROJECT))
Loading
Loading
Loading
Loading
@@ -52,10 +52,10 @@ class SettingsActivity : BaseActivity() {
}
 
bindPrefs()
switchRequireAuth.setOnCheckedChangeListener { compoundButton, b -> App.get().prefs.isRequireDeviceAuth = b }
switchRequireAuth.setOnCheckedChangeListener { compoundButton, b -> App.get().prefs.setRequiredDeviceAuth(b) }
}
 
fun bindPrefs() {
switchRequireAuth.isChecked = App.get().prefs.isRequireDeviceAuth
switchRequireAuth.isChecked = App.get().prefs.isRequiredDeviceAuth()
}
}
Loading
Loading
@@ -44,7 +44,7 @@ class TodosActivity : BaseActivity() {
 
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
App.get().prefs.startingView = Prefs.STARTING_VIEW_TODOS
App.get().prefs.setStartingView(Prefs.STARTING_VIEW_TODOS)
setContentView(R.layout.activity_todos)
ButterKnife.bind(this)
App.bus().register(this)
Loading
Loading
package com.commit451.gitlab.data;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import com.bluelinelabs.logansquare.LoganSquare;
import com.commit451.gitlab.model.Account;
import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
/**
* Shared prefs things
*/
public class Prefs {
private static final String KEY_ACCOUNTS = "accounts";
private static final String KEY_STARTING_VIEW = "starting_view";
private static final String KEY_REQUIRE_DEVICE_AUTH = "require_device_auth";
public static final int STARTING_VIEW_PROJECTS = 0;
public static final int STARTING_VIEW_GROUPS = 1;
public static final int STARTING_VIEW_ACTIVITY = 2;
public static final int STARTING_VIEW_TODOS = 3;
@Retention(RetentionPolicy.SOURCE)
@IntDef({STARTING_VIEW_PROJECTS, STARTING_VIEW_GROUPS, STARTING_VIEW_ACTIVITY, STARTING_VIEW_TODOS})
public @interface StartingView {
}
private SharedPreferences prefs;
public Prefs(Context context) {
if (!(context instanceof Application)) {
throw new IllegalArgumentException("This should be the application context. Not the activity context");
}
prefs = PreferenceManager.getDefaultSharedPreferences(context);
}
@NonNull
public List<Account> getAccounts() {
String accountsJson = prefs.getString(KEY_ACCOUNTS, null);
if (!TextUtils.isEmpty(accountsJson)) {
try {
return LoganSquare.parseList(accountsJson, Account.class);
} catch (IOException e) {
//why would this ever happen?!?!?1
prefs.edit().remove(KEY_ACCOUNTS).apply();
}
return new ArrayList<>();
} else {
return new ArrayList<>();
}
}
public void addAccount(Account account) {
List<Account> accounts = getAccounts();
accounts.add(account);
setAccounts(accounts);
}
public void removeAccount(Account account) {
List<Account> accounts = getAccounts();
accounts.remove(account);
setAccounts(accounts);
}
public void updateAccount(Account account) {
List<Account> accounts = getAccounts();
accounts.remove(account);
accounts.add(account);
setAccounts(accounts);
}
private void setAccounts(List<Account> accounts) {
try {
String json = LoganSquare.serialize(accounts);
prefs.edit()
.putString(KEY_ACCOUNTS, json)
.apply();
} catch (IOException e) {
//this wont happen! Right?!?!?!
}
}
@StartingView
public int getStartingView() {
@StartingView
int start = prefs.getInt(KEY_STARTING_VIEW, STARTING_VIEW_PROJECTS);
return start;
}
public void setStartingView(@StartingView int startingView) {
prefs.edit()
.putInt(KEY_STARTING_VIEW, startingView)
.apply();
}
public boolean isRequireDeviceAuth() {
return prefs.getBoolean(KEY_REQUIRE_DEVICE_AUTH, false);
}
public void setRequireDeviceAuth(boolean require) {
prefs.edit()
.putBoolean(KEY_REQUIRE_DEVICE_AUTH, require)
.apply();
}
}
package com.commit451.gitlab.data
import android.app.Application
import android.content.Context
import android.content.SharedPreferences
import android.preference.PreferenceManager
import android.support.annotation.IntDef
import com.bluelinelabs.logansquare.LoganSquare
import com.commit451.gitlab.model.Account
import java.io.IOException
import java.util.*
/**
* Shared prefs things
*/
class Prefs(context: Context) {
companion object {
val KEY_ACCOUNTS = "accounts"
val KEY_STARTING_VIEW = "starting_view"
val KEY_REQUIRE_DEVICE_AUTH = "require_device_auth"
const val STARTING_VIEW_PROJECTS = 0
const val STARTING_VIEW_GROUPS = 1
const val STARTING_VIEW_ACTIVITY = 2
const val STARTING_VIEW_TODOS = 3
@Retention(AnnotationRetention.SOURCE)
@IntDef(STARTING_VIEW_PROJECTS.toLong(), STARTING_VIEW_GROUPS.toLong(), STARTING_VIEW_ACTIVITY.toLong(), STARTING_VIEW_TODOS.toLong())
annotation class StartingView
}
private val prefs: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
init {
if (context !is Application) {
throw IllegalArgumentException("This should be the application context. Not the activity context")
}
}
fun getAccounts(): MutableList<Account> {
val accountsJson = prefs.getString(KEY_ACCOUNTS, null)
if (!accountsJson.isNullOrEmpty()) {
try {
return LoganSquare.parseList(accountsJson, Account::class.java)
} catch (e: IOException) {
prefs.edit().remove(KEY_ACCOUNTS).apply()
}
return ArrayList()
} else {
return ArrayList()
}
}
fun setAccounts(accounts: List<Account>) {
try {
val json = LoganSquare.serialize<List<Account>>(accounts)
prefs.edit()
.putString(KEY_ACCOUNTS, json)
.apply()
} catch (e: IOException) {
prefs.edit()
.remove(KEY_ACCOUNTS)
.apply()
}
}
fun addAccount(account: Account) {
val accounts = getAccounts()
accounts.add(account)
setAccounts(accounts)
}
fun removeAccount(account: Account) {
val accounts = getAccounts()
accounts.remove(account)
setAccounts(accounts)
}
fun updateAccount(account: Account) {
val accounts = getAccounts()
accounts.remove(account)
accounts.add(account)
setAccounts(accounts)
}
fun getStartingView(): Int {
@StartingView
val start = prefs.getInt(KEY_STARTING_VIEW, STARTING_VIEW_PROJECTS)
return start
}
fun setStartingView(@StartingView startingView: Int) {
prefs.edit()
.putInt(KEY_STARTING_VIEW, startingView)
.apply()
}
fun isRequiredDeviceAuth(): Boolean {
return prefs.getBoolean(KEY_REQUIRE_DEVICE_AUTH, false)
}
fun setRequiredDeviceAuth(require: Boolean) {
prefs.edit()
.putBoolean(KEY_REQUIRE_DEVICE_AUTH, require)
.apply()
}
}
package com.commit451.gitlab.dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Toast;
import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.afollestad.materialdialogs.Theme;
import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.gitlab.model.api.Group;
import com.commit451.gitlab.model.api.Member;
import com.commit451.gitlab.rx.CustomSingleObserver;
import java.util.Arrays;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import timber.log.Timber;
/**
* Change a users access level, either for a group or for a project
*/
public class AccessDialog extends MaterialDialog {
OnAccessChangedListener onAccessChangedListener;
Listener listener;
String[] roleNames;
long projectId = -1;
Group group;
Member member;
public AccessDialog(Context context, Listener accessAppliedListener) {
this(context, null, null, -1);
listener = accessAppliedListener;
}
public AccessDialog(Context context, Member member, Group group) {
this(context, member, group, -1);
}
public AccessDialog(Context context, Member member, long projectId) {
this(context, member, null, projectId);
}
private AccessDialog(Context context, Member member, Group group, long projectId) {
super(new MaterialDialog.Builder(context)
.items((group == null) ? R.array.project_role_names : R.array.group_role_names)
.itemsCallbackSingleChoice(-1, new ListCallbackSingleChoice() {
@Override
public boolean onSelection(MaterialDialog materialDialog, View view, int i, CharSequence charSequence) {
return true;
}
})
.theme(Theme.DARK)
.progress(true, 0) // So we can later show loading progress
.positiveText(R.string.action_apply)
.negativeText(R.string.md_cancel_label));
roleNames = getContext().getResources().getStringArray((group == null)
? R.array.project_role_names
: R.array.group_role_names);
getActionButton(DialogAction.POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onApply();
}
});
getActionButton(DialogAction.NEGATIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onCancel();
}
});
this.member = member;
this.group = group;
this.projectId = projectId;
if (this.member != null) {
setSelectedIndex(Arrays.asList(roleNames).indexOf(
Member.getAccessLevel(this.member.getAccessLevel())));
}
}
private void changeAccess(int accessLevel) {
if (group != null) {
showLoading();
editGroupOrProjectMember(App.get().getGitLab().editGroupMember(group.getId(), member.getId(), accessLevel));
} else if (projectId != -1) {
showLoading();
editGroupOrProjectMember(App.get().getGitLab().editProjectMember(projectId, member.getId(), accessLevel));
} else if (listener != null) {
listener.onAccessApplied(accessLevel);
} else {
throw new IllegalStateException("Not sure what to apply this access change to. Check the constructors plz");
}
}
private void editGroupOrProjectMember(Single<Member> observable) {
observable
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new CustomSingleObserver<Member>() {
@Override
public void error(@NonNull Throwable t) {
Timber.e(t);
AccessDialog.this.onError();
}
@Override
public void success(@NonNull Member member) {
if (onAccessChangedListener != null) {
onAccessChangedListener.onAccessChanged(AccessDialog.this.member, roleNames[getSelectedIndex()]);
}
dismiss();
}
});
}
public void showLoading() {
getActionButton(DialogAction.POSITIVE).setEnabled(false);
}
private void onError() {
Toast.makeText(getContext(), R.string.failed_to_apply_access_level, Toast.LENGTH_SHORT).show();
dismiss();
}
public void setOnAccessChangedListener(OnAccessChangedListener listener) {
onAccessChangedListener = listener;
}
private void onApply() {
if (getSelectedIndex() == -1) {
Toast.makeText(getContext(), R.string.please_select_access_level, Toast.LENGTH_LONG)
.show();
return;
}
String accessLevel = roleNames[getSelectedIndex()];
if (accessLevel == null) {
Toast.makeText(getContext(), R.string.please_select_access_level, Toast.LENGTH_LONG)
.show();
} else {
changeAccess(Member.getAccessLevel(accessLevel));
}
}
private void onCancel() {
dismiss();
}
public interface OnAccessChangedListener {
void onAccessChanged(Member member, String accessLevel);
}
public interface Listener {
void onAccessApplied(int accessLevel);
}
}
package com.commit451.gitlab.dialog
import android.content.Context
import android.widget.Toast
import com.afollestad.materialdialogs.DialogAction
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.Theme
import com.commit451.gitlab.App
import com.commit451.gitlab.R
import com.commit451.gitlab.model.api.Group
import com.commit451.gitlab.model.api.Member
import com.commit451.gitlab.rx.CustomSingleObserver
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import timber.log.Timber
import java.util.*
/**
* Change a users access level, either for a group or for a project
*/
class AccessDialog private constructor(context: Context, internal var member: Member?, internal var group: Group?, projectId: Long) : MaterialDialog(MaterialDialog.Builder(context)
.items(if (group == null) R.array.project_role_names else R.array.group_role_names)
.itemsCallbackSingleChoice(-1) { materialDialog, view, i, charSequence -> true }
.theme(Theme.DARK)
.progress(true, 0) // So we can later show loading progress
.positiveText(R.string.action_apply)
.negativeText(R.string.md_cancel_label)) {
private var onAccessChangedListener: OnAccessChangedListener? = null
var listener: Listener? = null
var roleNames: Array<String> = getContext().resources.getStringArray(if (group == null)
R.array.project_role_names
else
R.array.group_role_names)
var projectId: Long = -1
constructor(context: Context, accessAppliedListener: Listener) : this(context, null, null, -1) {
listener = accessAppliedListener
}
constructor(context: Context, member: Member, group: Group) : this(context, member, group, -1) {}
constructor(context: Context, member: Member, projectId: Long) : this(context, member, null, projectId) {}
init {
getActionButton(DialogAction.POSITIVE).setOnClickListener { onApply() }
getActionButton(DialogAction.NEGATIVE).setOnClickListener { onCancel() }
this.projectId = projectId
if (this.member != null) {
selectedIndex = Arrays.asList(*roleNames).indexOf(
Member.getAccessLevel(this.member!!.accessLevel))
}
}
fun changeAccess(accessLevel: Int) {
if (group != null) {
showLoading()
editGroupOrProjectMember(App.get().gitLab.editGroupMember(group!!.id, member!!.id, accessLevel))
} else if (projectId != -1L) {
showLoading()
editGroupOrProjectMember(App.get().gitLab.editProjectMember(projectId, member!!.id, accessLevel))
} else if (listener != null) {
listener!!.onAccessApplied(accessLevel)
} else {
throw IllegalStateException("Not sure what to apply this access change to. Check the constructors plz")
}
}
fun editGroupOrProjectMember(observable: Single<Member>) {
observable
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : CustomSingleObserver<Member>() {
override fun error(t: Throwable) {
Timber.e(t)
this@AccessDialog.onError()
}
override fun success(member: Member) {
if (onAccessChangedListener != null) {
onAccessChangedListener!!.onAccessChanged(this@AccessDialog.member!!, roleNames[selectedIndex])
}
dismiss()
}
})
}
fun showLoading() {
getActionButton(DialogAction.POSITIVE).isEnabled = false
}
fun onError() {
Toast.makeText(context, R.string.failed_to_apply_access_level, Toast.LENGTH_SHORT).show()
dismiss()
}
fun setOnAccessChangedListener(listener: OnAccessChangedListener) {
onAccessChangedListener = listener
}
fun onApply() {
if (selectedIndex == -1) {
Toast.makeText(context, R.string.please_select_access_level, Toast.LENGTH_LONG)
.show()
return
}
val accessLevel = roleNames[selectedIndex]
if (accessLevel == null) {
Toast.makeText(context, R.string.please_select_access_level, Toast.LENGTH_LONG)
.show()
} else {
changeAccess(Member.getAccessLevel(accessLevel))
}
}
fun onCancel() {
dismiss()
}
interface OnAccessChangedListener {
fun onAccessChanged(member: Member, accessLevel: String)
}
interface Listener {
fun onAccessApplied(accessLevel: Int)
}
}
package com.commit451.gitlab.dialog;
import android.content.Context;
import android.support.v7.app.AppCompatDialog;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.commit451.gitlab.R;
import butterknife.BindView;
import butterknife.ButterKnife;
public class HttpLoginDialog extends AppCompatDialog {
@BindView(R.id.message_text)
TextView textMessage;
@BindView(R.id.login_username)
EditText textUsername;
@BindView(R.id.login_password)
EditText textPassword;
@BindView(R.id.ok_button)
Button buttonOk;
@BindView(R.id.cancel_button)
Button buttonCancel;
public HttpLoginDialog(Context context, String realm, final LoginListener loginListener) {
super(context);
setContentView(R.layout.dialog_http_login);
ButterKnife.bind(this);
textMessage.setText(String.format(context.getResources().getString(R.string.realm_message), realm));
buttonOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loginListener.onLogin(textUsername.getText().toString(), textPassword.getText().toString());
HttpLoginDialog.this.dismiss();
}
});
buttonCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loginListener.onCancel();
HttpLoginDialog.this.dismiss();
}
});
setTitle(R.string.login_activity);
}
public interface LoginListener {
void onLogin(String username, String password);
void onCancel();
}
}
package com.commit451.gitlab.dialog
import android.content.Context
import android.support.v7.app.AppCompatDialog
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import butterknife.BindView
import butterknife.ButterKnife
import com.commit451.gitlab.R
class HttpLoginDialog(context: Context, realm: String, loginListener: HttpLoginDialog.LoginListener) : AppCompatDialog(context) {
@BindView(R.id.message_text)
lateinit var textMessage: TextView
@BindView(R.id.login_username)
lateinit var textUsername: EditText
@BindView(R.id.login_password)
lateinit var textPassword: EditText
@BindView(R.id.ok_button)
lateinit var buttonOk: Button
@BindView(R.id.cancel_button)
lateinit var buttonCancel: Button
init {
setContentView(R.layout.dialog_http_login)
ButterKnife.bind(this)
textMessage.text = String.format(context.resources.getString(R.string.realm_message), realm)
buttonOk.setOnClickListener {
loginListener.onLogin(textUsername.text.toString(), textPassword.text.toString())
this@HttpLoginDialog.dismiss()
}
buttonCancel.setOnClickListener {
loginListener.onCancel()
this@HttpLoginDialog.dismiss()
}
setTitle(R.string.login_activity)
}
interface LoginListener {
fun onLogin(username: String, password: String)
fun onCancel()
}
}
Loading
Loading
@@ -107,7 +107,11 @@ class GroupMembersFragment : ButterKnifeFragment() {
 
override fun onUserChangeAccessClicked(member: Member) {
val accessDialog = AccessDialog(activity, member, group)
accessDialog.setOnAccessChangedListener { member, accessLevel -> loadData() }
accessDialog.setOnAccessChangedListener(object : AccessDialog.OnAccessChangedListener {
override fun onAccessChanged(member: Member, accessLevel: String) {
loadData()
}
})
accessDialog.show()
}
}
Loading
Loading
Loading
Loading
@@ -115,7 +115,11 @@ class ProjectMembersFragment : ButterKnifeFragment() {
 
override fun onChangeAccess(member: Member) {
val accessDialog = AccessDialog(activity, member, project!!.id)
accessDialog.setOnAccessChangedListener { member, accessLevel -> loadData() }
accessDialog.setOnAccessChangedListener(object : AccessDialog.OnAccessChangedListener {
override fun onAccessChanged(member: Member, accessLevel: String) {
loadData()
}
})
accessDialog.show()
}
 
Loading
Loading
Loading
Loading
@@ -150,24 +150,24 @@ class ProjectsFragment : ButterKnifeFragment() {
when (mode) {
MODE_ALL -> {
showLoading()
actuallyLoadIt(gitLab.allProjects)
actuallyLoadIt(getGitLab().allProjects)
}
MODE_MINE -> {
showLoading()
actuallyLoadIt(gitLab.myProjects)
actuallyLoadIt(getGitLab().myProjects)
}
MODE_STARRED -> {
showLoading()
actuallyLoadIt(gitLab.starredProjects)
actuallyLoadIt(getGitLab().starredProjects)
}
MODE_SEARCH -> if (query != null) {
showLoading()
actuallyLoadIt(gitLab.searchAllProjects(query))
actuallyLoadIt(getGitLab().searchAllProjects(query))
}
MODE_GROUP -> {
showLoading()
val group = Parcels.unwrap<Group>(arguments.getParcelable<Parcelable>(EXTRA_GROUP)) ?: throw IllegalStateException("You must also pass a group if you want to show a groups projects")
actuallyLoadIt(gitLab.getGroupProjects(group.id))
actuallyLoadIt(getGitLab().getGroupProjects(group.id))
}
else -> throw IllegalStateException(mode.toString() + " is not defined")
}
Loading
Loading
@@ -214,7 +214,7 @@ class ProjectsFragment : ButterKnifeFragment() {
loading = true
adapterProjects.setLoading(true)
Timber.d("loadMore called for %s", nextPageUrl)
gitLab.getProjects(nextPageUrl!!.toString())
getGitLab().getProjects(nextPageUrl!!.toString())
.compose(this.bindToLifecycle<Response<List<Project>>>())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
Loading
Loading
@@ -247,18 +247,17 @@ class ProjectsFragment : ButterKnifeFragment() {
loadData()
}
 
private val gitLab: GitLab
get() {
if (listener != null) {
return listener!!.gitLab
} else {
return App.get().gitLab
}
fun getGitLab(): GitLab {
if (listener != null) {
return listener!!.getGitLab()
} else {
return App.get().gitLab
}
}
 
interface Listener {
fun onProjectClicked(project: Project)
 
val gitLab: GitLab
fun getGitLab(): GitLab
}
}
Loading
Loading
@@ -198,7 +198,7 @@ class LabCoatNavigationView : NavigationView {
}
 
fun setAccounts() {
val accounts = App.get().prefs.accounts
val accounts = App.get().prefs.getAccounts()
Timber.d("Got %s accounts", accounts.size)
Collections.sort(accounts)
Collections.reverse(accounts)
Loading
Loading
package com.commit451.gitlab.widget;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.alexgwyn.recyclerviewsquire.TypedViewHolder;
import com.commit451.gitlab.R;
import com.commit451.gitlab.model.Account;
import com.commit451.gitlab.transformation.CircleTransformation;
import com.commit451.gitlab.util.ImageUtil;
import com.squareup.picasso.Picasso;
import butterknife.BindView;
import butterknife.ButterKnife;
/**
* A signed in account
*/
public class AccountViewHolder extends TypedViewHolder<Account> {
public static AccountViewHolder inflate(ViewGroup parent) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.widget_item_account, parent, false);
return new AccountViewHolder(view);
}
@BindView(R.id.account_image)
ImageView image;
@BindView(R.id.account_username)
TextView textUsername;
@BindView(R.id.account_server)
TextView textServer;
public AccountViewHolder(View view) {
super(view);
ButterKnife.bind(this, view);
}
@Override
public void bind(int position, Account item) {
textServer.setText(item.getServerUrl().toString());
textUsername.setText(item.getUser().getUsername());
Picasso.with(getContext())
.load(ImageUtil.getAvatarUrl(item.getUser(), itemView.getResources().getDimensionPixelSize(R.dimen.user_list_image_size)))
.transform(new CircleTransformation())
.into(image);
}
}
package com.commit451.gitlab.widget
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import butterknife.BindView
import butterknife.ButterKnife
import com.alexgwyn.recyclerviewsquire.TypedViewHolder
import com.commit451.gitlab.R
import com.commit451.gitlab.model.Account
import com.commit451.gitlab.transformation.CircleTransformation
import com.commit451.gitlab.util.ImageUtil
import com.squareup.picasso.Picasso
/**
* A signed in account
*/
class AccountViewHolder(view: View) : TypedViewHolder<Account>(view) {
companion object {
fun inflate(parent: ViewGroup): AccountViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.widget_item_account, parent, false)
return AccountViewHolder(view)
}
}
@BindView(R.id.account_image) lateinit var image: ImageView
@BindView(R.id.account_username) lateinit var textUsername: TextView
@BindView(R.id.account_server) lateinit var textServer: TextView
init {
ButterKnife.bind(this, view)
}
override fun bind(position: Int, item: Account) {
textServer.text = item.serverUrl.toString()
textUsername.text = item.user.username
Picasso.with(context)
.load(ImageUtil.getAvatarUrl(item.user, itemView.resources.getDimensionPixelSize(R.dimen.user_list_image_size)))
.transform(CircleTransformation())
.into(image)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment