Some refactoring

This commit is contained in:
Paul Schaub 2018-02-10 17:34:01 +01:00
parent 70b44820fd
commit 964c4da15f
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
20 changed files with 251 additions and 40 deletions

View File

@ -0,0 +1,7 @@
<component name="ProjectDictionaryState">
<dictionary name="vanitas">
<words>
<w>schaub</w>
</words>
</dictionary>
</component>

View File

@ -24,7 +24,7 @@
</value> </value>
</option> </option>
</component> </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" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View File

@ -34,10 +34,10 @@ dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.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-android-extensions:$smackVersion"
//compile "org.igniterealtime.smack:smack-omemo-signal:$smackVersion" compile "org.igniterealtime.smack:smack-omemo-signal:$smackVersion"
//compile "org.igniterealtime.smack:smack-tcp:$smackVersion" compile "org.igniterealtime.smack:smack-tcp:$smackVersion"
//compile "org.igniterealtime.smack:smack-experimental:$smackVersion" compile "org.igniterealtime.smack:smack-experimental:$smackVersion"
compile 'com.jakewharton:butterknife:8.8.1' compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

View File

@ -16,7 +16,7 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Slam"> android:theme="@style/Slam">
<activity <activity
android:name=".activity.LoginActivity" android:name=".mvp.view.LoginActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:windowSoftInputMode="adjustResize"> android:windowSoftInputMode="adjustResize">
<intent-filter> <intent-filter>
@ -25,7 +25,7 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".activity.MainActivity" /> <activity android:name=".mvp.view.MainActivity" />
<meta-data <meta-data
android:name="com.google.android.gms.car.application" android:name="com.google.android.gms.car.application"

View File

@ -4,9 +4,9 @@ import android.text.Editable;
import android.text.TextWatcher; 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 @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// Do nothing // Do nothing
@ -16,4 +16,9 @@ public abstract class AfterTextChangedListener implements TextWatcher {
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
// Do nothing // Do nothing
} }
@Override
public void afterTextChanged(Editable s) {
// Do nothing
}
} }

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -1,4 +1,4 @@
package de.vanitasvitae.slam.mvp_contracts; package de.vanitasvitae.slam.mvp.contracts;
/** /**
* Model-View-Presenter contract of the login screen. * Model-View-Presenter contract of the login screen.

View File

@ -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();
}
}

View File

@ -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() {
}
}

View File

@ -1,12 +1,16 @@
package de.vanitasvitae.slam.activity; package de.vanitasvitae.slam.mvp.presenter.dummy;
import android.os.Handler; 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. * Dummy presenter, that has no model.
* This is used to demonstrate the capabilities of the view. * This is used to demonstrate the capabilities of the view.
*
* Created by Paul Schaub on 01.02.18. * Created by Paul Schaub on 01.02.18.
*/ */
public class DummyLoginPresenter implements LoginContract.Presenter { public class DummyLoginPresenter implements LoginContract.Presenter {
@ -19,10 +23,12 @@ public class DummyLoginPresenter implements LoginContract.Presenter {
@Override @Override
public void jidChanged(String jid) { public void jidChanged(String jid) {
if (jid.length() < 10) { // Check if jid is valid XMPP ID.
view.showInvalidJidError(); try {
} else { JidCreate.entityBareFrom(jid);
view.hideInvalidJidError(); view.hideInvalidJidError();
} catch (XmppStringprepException e) {
view.showInvalidJidError();
} }
} }

View File

@ -1,4 +1,4 @@
package de.vanitasvitae.slam.activity; package de.vanitasvitae.slam.mvp.view;
import android.app.Fragment; import android.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
@ -16,9 +16,11 @@ import de.vanitasvitae.slam.R;
import de.vanitasvitae.slam.ui.ChatMessageEntry; import de.vanitasvitae.slam.ui.ChatMessageEntry;
/** /**
* Fragment that shows the conversation with a user.
*
* Created by Paul Schaub on 30.01.18. * Created by Paul Schaub on 30.01.18.
*/ */
public class ChatFragment extends Fragment { public class ConversationFragment extends Fragment {
@BindView(R.id.recycler_chat) @BindView(R.id.recycler_chat)
RecyclerView recyclerView; RecyclerView recyclerView;

View File

@ -1,24 +1,24 @@
package de.vanitasvitae.slam.activity; package de.vanitasvitae.slam.mvp.view;
import android.app.Fragment; import android.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import de.vanitasvitae.slam.R; 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. * Created by Paul Schaub on 30.01.18.
*/ */
public class ChatListFragment extends Fragment { public class ConversationListFragment extends Fragment {
@BindView(R.id.recycler_chatlist) @BindView(R.id.recycler_chatlist)
RecyclerView recyclerView; RecyclerView recyclerView;
@ -39,21 +39,21 @@ public class ChatListFragment extends Fragment {
final boolean[] reads = {true, false, true}; final boolean[] reads = {true, false, true};
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.setAdapter(new RecyclerView.Adapter<ChatListEntry>() { recyclerView.setAdapter(new RecyclerView.Adapter<ConversationEntry>() {
@Override @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); View view1 = LayoutInflater.from(getActivity()).inflate(R.layout.chatlist_singlechat, parent, false);
view1.setOnClickListener(new View.OnClickListener() { view1.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { 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 @Override
public void onBindViewHolder(ChatListEntry holder, int position) { public void onBindViewHolder(ConversationEntry holder, int position) {
holder.bind( holder.bind(
usernames[position], usernames[position],
messages[position], messages[position],

View File

@ -1,4 +1,4 @@
package de.vanitasvitae.slam.activity; package de.vanitasvitae.slam.mvp.view;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
@ -17,11 +17,12 @@ import android.widget.Toast;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
import de.vanitasvitae.slam.AfterTextChangedListener; import de.vanitasvitae.slam.AbstractTextWatcher;
import de.vanitasvitae.slam.EditorActionDoneListener; import de.vanitasvitae.slam.EditorActionDoneListener;
import de.vanitasvitae.slam.R; import de.vanitasvitae.slam.R;
import de.vanitasvitae.slam.activity.abstr.ThemedAppCompatActivity; import de.vanitasvitae.slam.mvp.view.abstr.ThemedAppCompatActivity;
import de.vanitasvitae.slam.mvp_contracts.LoginContract; import de.vanitasvitae.slam.mvp.presenter.dummy.DummyLoginPresenter;
import de.vanitasvitae.slam.mvp.contracts.LoginContract;
public class LoginActivity extends ThemedAppCompatActivity implements LoginContract.View { 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 @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
presenter.jidChanged(s.toString()); presenter.jidChanged(s.toString());
} }
}); });
inputPassword.addTextChangedListener(new AfterTextChangedListener() { inputPassword.addTextChangedListener(new AbstractTextWatcher() {
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
presenter.passwordChanged(s.toString()); presenter.passwordChanged(s.toString());

View File

@ -1,4 +1,4 @@
package de.vanitasvitae.slam.activity; package de.vanitasvitae.slam.mvp.view;
import android.app.Fragment; import android.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
@ -13,9 +13,11 @@ import android.widget.FrameLayout;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import de.vanitasvitae.slam.R; 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. * Created by vanitas on 22.01.18.
*/ */
public class MainActivity extends ThemedAppCompatActivity { 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); this, drawerLayout, toolbar, R.string.error_incorrect_password, R.string.error_invalid_jid);
drawerLayout.addDrawerListener(drawerToggle); drawerLayout.addDrawerListener(drawerToggle);
Fragment chatListFragment = new ChatListFragment(); Fragment chatListFragment = new ConversationListFragment();
Log.d(TAG, "Begin Transaction"); Log.d(TAG, "Begin Transaction");
getFragmentManager().beginTransaction().add(R.id.fragment_container, chatListFragment).commit(); getFragmentManager().beginTransaction().add(R.id.fragment_container, chatListFragment).commit();
} }

View File

@ -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() {
}
}

View File

@ -1,4 +1,4 @@
package de.vanitasvitae.slam.activity.abstr; package de.vanitasvitae.slam.mvp.view.abstr;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Intent; import android.content.Intent;

View File

@ -9,11 +9,11 @@ import de.vanitasvitae.slam.R;
/** /**
* Created by Paul Schaub on 30.01.18. * Created by Paul Schaub on 30.01.18.
*/ */
public class ChatListEntry extends RecyclerView.ViewHolder { public class ConversationEntry extends RecyclerView.ViewHolder {
private View view; private View view;
public ChatListEntry(View itemView) { public ConversationEntry(View itemView) {
super(itemView); super(itemView);
this.view = itemView; this.view = itemView;
} }

View File

@ -16,7 +16,7 @@
android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_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"> android:background="@drawable/material_bg">
<RelativeLayout <RelativeLayout