Some refactoring
This commit is contained in:
parent
70b44820fd
commit
964c4da15f
|
@ -0,0 +1,7 @@
|
|||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="vanitas">
|
||||
<words>
|
||||
<w>schaub</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
</component>
|
|
@ -24,7 +24,7 @@
|
|||
</value>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
|
|
@ -34,10 +34,10 @@ dependencies {
|
|||
androidTestImplementation 'com.android.support.test:runner:1.0.1'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
|
||||
|
||||
//compile "org.igniterealtime.smack:smack-android-extensions:$smackVersion"
|
||||
//compile "org.igniterealtime.smack:smack-omemo-signal:$smackVersion"
|
||||
//compile "org.igniterealtime.smack:smack-tcp:$smackVersion"
|
||||
//compile "org.igniterealtime.smack:smack-experimental:$smackVersion"
|
||||
compile "org.igniterealtime.smack:smack-android-extensions:$smackVersion"
|
||||
compile "org.igniterealtime.smack:smack-omemo-signal:$smackVersion"
|
||||
compile "org.igniterealtime.smack:smack-tcp:$smackVersion"
|
||||
compile "org.igniterealtime.smack:smack-experimental:$smackVersion"
|
||||
|
||||
compile 'com.jakewharton:butterknife:8.8.1'
|
||||
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
android:supportsRtl="true"
|
||||
android:theme="@style/Slam">
|
||||
<activity
|
||||
android:name=".activity.LoginActivity"
|
||||
android:name=".mvp.view.LoginActivity"
|
||||
android:label="@string/app_name"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<intent-filter>
|
||||
|
@ -25,7 +25,7 @@
|
|||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".activity.MainActivity" />
|
||||
<activity android:name=".mvp.view.MainActivity" />
|
||||
|
||||
<meta-data
|
||||
android:name="com.google.android.gms.car.application"
|
||||
|
|
|
@ -4,9 +4,9 @@ import android.text.Editable;
|
|||
import android.text.TextWatcher;
|
||||
|
||||
/**
|
||||
* Abstract TextWatcher, that has method stubs for all methods except {@link TextWatcher#afterTextChanged(Editable)}.
|
||||
* Abstract TextWatcher, that has method stubs for all methods..
|
||||
*/
|
||||
public abstract class AfterTextChangedListener implements TextWatcher {
|
||||
public abstract class AbstractTextWatcher implements TextWatcher {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
// Do nothing
|
||||
|
@ -16,4 +16,9 @@ public abstract class AfterTextChangedListener implements TextWatcher {
|
|||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package de.vanitasvitae.slam.mvp.contracts;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.vanitasvitae.slam.mvp.view.ConversationListFragment;
|
||||
|
||||
/**
|
||||
* Model-View-Presenter contract for the {@link ConversationListFragment}.
|
||||
*
|
||||
* Created by Paul Schaub on 01.02.18.
|
||||
*/
|
||||
public interface ContactListContract {
|
||||
|
||||
interface View {
|
||||
void addContactListItems(List<?> contacts);
|
||||
void clearContactListItems();
|
||||
void onUpdateContactPresence();
|
||||
void showContactListLoadingIndicator();
|
||||
void hideContactListLoadingIndicator();
|
||||
}
|
||||
|
||||
interface Presenter {
|
||||
void onContactListItemClick();
|
||||
void onContactListItemLongClick();
|
||||
void addNewContact();
|
||||
void deleteContact();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package de.vanitasvitae.slam.mvp.contracts;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.vanitasvitae.slam.mvp.view.ConversationFragment;
|
||||
|
||||
/**
|
||||
* Model-View-Presenter contract for the {@link ConversationFragment}.
|
||||
* Created by Paul Schaub on 01.02.18.
|
||||
*/
|
||||
public interface ConversationContract {
|
||||
|
||||
interface View {
|
||||
void addMessageItems(List<?> messages, boolean end);
|
||||
void highlightMessageItem();
|
||||
void correctMessageItem();
|
||||
void navigateToContactProfile();
|
||||
}
|
||||
|
||||
interface Presenter {
|
||||
void onConversationScrolledToTop();
|
||||
void onComposingMessageChanged(String composingMessage);
|
||||
void onMessageItemClick();
|
||||
void onMessageItemLongClick();
|
||||
void onMessageItemSenderClick();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package de.vanitasvitae.slam.mvp.contracts;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Model-View-Presenter contract of the conversation list fragment.
|
||||
* Created by Paul Schaub on 01.02.18.
|
||||
*/
|
||||
public interface ConversationListContract {
|
||||
|
||||
interface View {
|
||||
void populateConversationList(List<?> conversations);
|
||||
}
|
||||
|
||||
interface Presenter {
|
||||
void onConversationClick();
|
||||
void onConversationLongClick();
|
||||
void load();
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package de.vanitasvitae.slam.mvp_contracts;
|
||||
package de.vanitasvitae.slam.mvp.contracts;
|
||||
|
||||
/**
|
||||
* Model-View-Presenter contract of the login screen.
|
|
@ -0,0 +1,25 @@
|
|||
package de.vanitasvitae.slam.mvp.contracts;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Model-View-Presenter contract for the {@link de.vanitasvitae.slam.mvp.view.SearchFragment}.
|
||||
* Created by Paul Schaub on 01.02.18.
|
||||
*/
|
||||
public interface SearchContract {
|
||||
|
||||
interface View {
|
||||
void addSearchResults(List<?> results);
|
||||
void clearSearchResults();
|
||||
void showLoadingIndicator();
|
||||
void hideLoadingIndicator();
|
||||
void showEmptySearchResults();
|
||||
void hideEmptySearchResults();
|
||||
}
|
||||
|
||||
interface Presenter {
|
||||
void onSearchQueryChanged(String query);
|
||||
void onSearchResultClick();
|
||||
void onSearchScrolledToBottom();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package de.vanitasvitae.slam.mvp.presenter;
|
||||
|
||||
import org.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
|
||||
import de.vanitasvitae.slam.mvp.contracts.LoginContract;
|
||||
|
||||
/**
|
||||
* Created by Paul Schaub on 01.02.18.
|
||||
*/
|
||||
public class LoginPresenter implements LoginContract.Presenter {
|
||||
|
||||
private final LoginContract.View view;
|
||||
|
||||
private BareJid jid;
|
||||
private String password;
|
||||
|
||||
public LoginPresenter(LoginContract.View view) {
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jidChanged(String jid) {
|
||||
try {
|
||||
this.jid = JidCreate.entityBareFrom(jid);
|
||||
view.hideInvalidJidError();
|
||||
} catch (XmppStringprepException e) {
|
||||
this.jid = null;
|
||||
view.showInvalidJidError();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void passwordChanged(String password) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loginClicked() {
|
||||
|
||||
}
|
||||
}
|
|
@ -1,12 +1,16 @@
|
|||
package de.vanitasvitae.slam.activity;
|
||||
package de.vanitasvitae.slam.mvp.presenter.dummy;
|
||||
|
||||
import android.os.Handler;
|
||||
|
||||
import de.vanitasvitae.slam.mvp_contracts.LoginContract;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
|
||||
import de.vanitasvitae.slam.mvp.contracts.LoginContract;
|
||||
|
||||
/**
|
||||
* Dummy presenter, that has no model.
|
||||
* This is used to demonstrate the capabilities of the view.
|
||||
*
|
||||
* Created by Paul Schaub on 01.02.18.
|
||||
*/
|
||||
public class DummyLoginPresenter implements LoginContract.Presenter {
|
||||
|
@ -19,10 +23,12 @@ public class DummyLoginPresenter implements LoginContract.Presenter {
|
|||
|
||||
@Override
|
||||
public void jidChanged(String jid) {
|
||||
if (jid.length() < 10) {
|
||||
view.showInvalidJidError();
|
||||
} else {
|
||||
// Check if jid is valid XMPP ID.
|
||||
try {
|
||||
JidCreate.entityBareFrom(jid);
|
||||
view.hideInvalidJidError();
|
||||
} catch (XmppStringprepException e) {
|
||||
view.showInvalidJidError();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package de.vanitasvitae.slam.activity;
|
||||
package de.vanitasvitae.slam.mvp.view;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.os.Bundle;
|
||||
|
@ -16,9 +16,11 @@ import de.vanitasvitae.slam.R;
|
|||
import de.vanitasvitae.slam.ui.ChatMessageEntry;
|
||||
|
||||
/**
|
||||
* Fragment that shows the conversation with a user.
|
||||
*
|
||||
* Created by Paul Schaub on 30.01.18.
|
||||
*/
|
||||
public class ChatFragment extends Fragment {
|
||||
public class ConversationFragment extends Fragment {
|
||||
|
||||
@BindView(R.id.recycler_chat)
|
||||
RecyclerView recyclerView;
|
|
@ -1,24 +1,24 @@
|
|||
package de.vanitasvitae.slam.activity;
|
||||
package de.vanitasvitae.slam.mvp.view;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import de.vanitasvitae.slam.R;
|
||||
import de.vanitasvitae.slam.ui.ChatListEntry;
|
||||
import de.vanitasvitae.slam.ui.ConversationEntry;
|
||||
|
||||
/**
|
||||
* Fragment that lists conversations the user takes part in.
|
||||
*
|
||||
* Created by Paul Schaub on 30.01.18.
|
||||
*/
|
||||
public class ChatListFragment extends Fragment {
|
||||
public class ConversationListFragment extends Fragment {
|
||||
|
||||
@BindView(R.id.recycler_chatlist)
|
||||
RecyclerView recyclerView;
|
||||
|
@ -39,21 +39,21 @@ public class ChatListFragment extends Fragment {
|
|||
final boolean[] reads = {true, false, true};
|
||||
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
recyclerView.setAdapter(new RecyclerView.Adapter<ChatListEntry>() {
|
||||
recyclerView.setAdapter(new RecyclerView.Adapter<ConversationEntry>() {
|
||||
@Override
|
||||
public ChatListEntry onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
public ConversationEntry onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view1 = LayoutInflater.from(getActivity()).inflate(R.layout.chatlist_singlechat, parent, false);
|
||||
view1.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.fragment_container, new ChatFragment()).commit();
|
||||
getFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.fragment_container, new ConversationFragment()).commit();
|
||||
}
|
||||
});
|
||||
return new ChatListEntry(view1);
|
||||
return new ConversationEntry(view1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ChatListEntry holder, int position) {
|
||||
public void onBindViewHolder(ConversationEntry holder, int position) {
|
||||
holder.bind(
|
||||
usernames[position],
|
||||
messages[position],
|
|
@ -1,4 +1,4 @@
|
|||
package de.vanitasvitae.slam.activity;
|
||||
package de.vanitasvitae.slam.mvp.view;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
@ -17,11 +17,12 @@ import android.widget.Toast;
|
|||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import de.vanitasvitae.slam.AfterTextChangedListener;
|
||||
import de.vanitasvitae.slam.AbstractTextWatcher;
|
||||
import de.vanitasvitae.slam.EditorActionDoneListener;
|
||||
import de.vanitasvitae.slam.R;
|
||||
import de.vanitasvitae.slam.activity.abstr.ThemedAppCompatActivity;
|
||||
import de.vanitasvitae.slam.mvp_contracts.LoginContract;
|
||||
import de.vanitasvitae.slam.mvp.view.abstr.ThemedAppCompatActivity;
|
||||
import de.vanitasvitae.slam.mvp.presenter.dummy.DummyLoginPresenter;
|
||||
import de.vanitasvitae.slam.mvp.contracts.LoginContract;
|
||||
|
||||
public class LoginActivity extends ThemedAppCompatActivity implements LoginContract.View {
|
||||
|
||||
|
@ -67,14 +68,14 @@ public class LoginActivity extends ThemedAppCompatActivity implements LoginContr
|
|||
}
|
||||
});
|
||||
|
||||
inputUsername.addTextChangedListener(new AfterTextChangedListener() {
|
||||
inputUsername.addTextChangedListener(new AbstractTextWatcher() {
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
presenter.jidChanged(s.toString());
|
||||
}
|
||||
});
|
||||
|
||||
inputPassword.addTextChangedListener(new AfterTextChangedListener() {
|
||||
inputPassword.addTextChangedListener(new AbstractTextWatcher() {
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
presenter.passwordChanged(s.toString());
|
|
@ -1,4 +1,4 @@
|
|||
package de.vanitasvitae.slam.activity;
|
||||
package de.vanitasvitae.slam.mvp.view;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.os.Bundle;
|
||||
|
@ -13,9 +13,11 @@ import android.widget.FrameLayout;
|
|||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import de.vanitasvitae.slam.R;
|
||||
import de.vanitasvitae.slam.activity.abstr.ThemedAppCompatActivity;
|
||||
import de.vanitasvitae.slam.mvp.view.abstr.ThemedAppCompatActivity;
|
||||
|
||||
/**
|
||||
* Main activity that hosts some fragments.
|
||||
*
|
||||
* Created by vanitas on 22.01.18.
|
||||
*/
|
||||
public class MainActivity extends ThemedAppCompatActivity {
|
||||
|
@ -48,7 +50,7 @@ public class MainActivity extends ThemedAppCompatActivity {
|
|||
this, drawerLayout, toolbar, R.string.error_incorrect_password, R.string.error_invalid_jid);
|
||||
drawerLayout.addDrawerListener(drawerToggle);
|
||||
|
||||
Fragment chatListFragment = new ChatListFragment();
|
||||
Fragment chatListFragment = new ConversationListFragment();
|
||||
Log.d(TAG, "Begin Transaction");
|
||||
getFragmentManager().beginTransaction().add(R.id.fragment_container, chatListFragment).commit();
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package de.vanitasvitae.slam.mvp.view;
|
||||
|
||||
import android.app.Fragment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.vanitasvitae.slam.mvp.contracts.SearchContract;
|
||||
|
||||
/**
|
||||
* Fragment that shows search results from contacts and messages (and maybe services?).
|
||||
*
|
||||
* Created by Paul Schaub on 01.02.18.
|
||||
*/
|
||||
public class SearchFragment extends Fragment implements SearchContract.View {
|
||||
|
||||
@Override
|
||||
public void addSearchResults(List<?> results) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearSearchResults() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showLoadingIndicator() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideLoadingIndicator() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showEmptySearchResults() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideEmptySearchResults() {
|
||||
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package de.vanitasvitae.slam.activity.abstr;
|
||||
package de.vanitasvitae.slam.mvp.view.abstr;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
|
@ -9,11 +9,11 @@ import de.vanitasvitae.slam.R;
|
|||
/**
|
||||
* Created by Paul Schaub on 30.01.18.
|
||||
*/
|
||||
public class ChatListEntry extends RecyclerView.ViewHolder {
|
||||
public class ConversationEntry extends RecyclerView.ViewHolder {
|
||||
|
||||
private View view;
|
||||
|
||||
public ChatListEntry(View itemView) {
|
||||
public ConversationEntry(View itemView) {
|
||||
super(itemView);
|
||||
this.view = itemView;
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context="de.vanitasvitae.slam.activity.LoginActivity"
|
||||
tools:context="de.vanitasvitae.slam.mvp.view.LoginActivity"
|
||||
android:background="@drawable/material_bg">
|
||||
|
||||
<RelativeLayout
|
||||
|
|
Loading…
Reference in New Issue