Small refactoring (now interfaces have prefix "I")

This commit is contained in:
ChronosX88 2019-03-29 12:40:24 +04:00
parent 6a5fdcb733
commit c42a00e6b7
32 changed files with 96 additions and 106 deletions

View File

@ -2,6 +2,6 @@ package io.github.chronosx88.influence.contracts;
import android.view.View;
public interface ItemClickListener {
public interface IItemClickListener {
void onItemClick(View view, int position);
}

View File

@ -4,6 +4,6 @@ import net.tomp2p.peers.PeerAddress;
import io.github.chronosx88.influence.models.roomEntities.MessageEntity;
public interface ChatLogicContract {
public interface IChatLogicContract {
void sendMessage(PeerAddress address, MessageEntity message);
}

View File

@ -1,6 +1,6 @@
package io.github.chronosx88.influence.contracts.chatactivity;
public interface ChatPresenterContract {
public interface IChatPresenterContract {
void sendMessage(String text);
void updateAdapter();
}

View File

@ -4,7 +4,7 @@ import java.util.List;
import io.github.chronosx88.influence.models.roomEntities.MessageEntity;
public interface ChatViewContract {
public interface IChatViewContract {
void updateMessageList(MessageEntity message);
void updateMessageList(List<MessageEntity> messages);
}

View File

@ -4,6 +4,6 @@ import java.util.List;
import io.github.chronosx88.influence.models.roomEntities.ChatEntity;
public interface ChatListLogicContract {
public interface IChatListLogicContract {
List<ChatEntity> loadAllChats();
}

View File

@ -2,7 +2,7 @@ package io.github.chronosx88.influence.contracts.chatlist;
import android.view.MenuItem;
public interface ChatListPresenterContract {
public interface IChatListPresenterContract {
void updateChatList();
void openChat(String chatID);
void onContextItemSelected(MenuItem item);

View File

@ -7,7 +7,7 @@ import java.util.List;
import io.github.chronosx88.influence.helpers.ChatListAdapter;
import io.github.chronosx88.influence.models.roomEntities.ChatEntity;
public interface ChatListViewContract {
public interface IChatListViewContract {
void setRecycleAdapter(ChatListAdapter adapter);
void startActivity(Intent intent);
void updateChatList(ChatListAdapter adapter, List<ChatEntity> chats);

View File

@ -1,6 +1,6 @@
package io.github.chronosx88.influence.contracts.mainactivity;
public interface MainLogicContract {
public interface IMainLogicContract {
void initPeer();
void shutdownPeer();
}

View File

@ -1,6 +1,6 @@
package io.github.chronosx88.influence.contracts.mainactivity;
public interface MainPresenterContract {
public interface IMainPresenterContract {
void initPeer();
void onDestroy();
}

View File

@ -1,5 +1,5 @@
package io.github.chronosx88.influence.contracts.mainactivity;
public interface MainViewContract {
public interface IMainViewContract {
//
}

View File

@ -1,5 +1,5 @@
package io.github.chronosx88.influence.contracts.observer;
public interface NetworkObserver {
public interface INetworkObserver {
void handleEvent(Object object);
}

View File

@ -0,0 +1,12 @@
package io.github.chronosx88.influence.contracts.observer;
import com.google.gson.JsonObject;
public interface IObservable {
void register(IObserver observer);
void register(INetworkObserver networkObserver);
void unregister(IObserver observer);
void unregister(INetworkObserver networkObserver);
void notifyUIObservers(JsonObject jsonObject);
void notifyNetworkObservers(Object object);
}

View File

@ -2,6 +2,6 @@ package io.github.chronosx88.influence.contracts.observer;
import com.google.gson.JsonObject;
public interface Observer {
public interface IObserver {
void handleEvent(JsonObject object);
}

View File

@ -1,12 +0,0 @@
package io.github.chronosx88.influence.contracts.observer;
import com.google.gson.JsonObject;
public interface Observable {
void register(Observer observer);
void register(NetworkObserver networkObserver);
void unregister(Observer observer);
void unregister(NetworkObserver networkObserver);
void notifyUIObservers(JsonObject jsonObject);
void notifyNetworkObservers(Object object);
}

View File

@ -1,5 +1,5 @@
package io.github.chronosx88.influence.contracts.startchat;
public interface StartChatLogicContract {
public interface IStartChatLogicContract {
void sendStartChatMessage(String peerID);
}

View File

@ -1,5 +1,5 @@
package io.github.chronosx88.influence.contracts.startchat;
public interface StartChatPresenterContract {
public interface IStartChatPresenterContract {
void startChatWithPeer(String peerID);
}

View File

@ -1,6 +1,6 @@
package io.github.chronosx88.influence.contracts.startchat;
public interface StartChatViewContract {
public interface IStartChatViewContract {
void showMessage(String message);
void showProgressDialog(boolean enabled);
}

View File

@ -12,15 +12,15 @@ import java.util.List;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import io.github.chronosx88.influence.R;
import io.github.chronosx88.influence.contracts.ItemClickListener;
import io.github.chronosx88.influence.contracts.IItemClickListener;
import io.github.chronosx88.influence.models.roomEntities.ChatEntity;
public class ChatListAdapter extends RecyclerView.Adapter<ChatListAdapter.ChatListViewHolder> {
List<ChatEntity> chatList = new ArrayList<>();
public int onClickPosition = -1;
private ItemClickListener itemClickListener;
private IItemClickListener itemClickListener;
public ChatListAdapter(ItemClickListener itemClickListener) {
public ChatListAdapter(IItemClickListener itemClickListener) {
this.itemClickListener = itemClickListener;
}

View File

@ -15,14 +15,14 @@ import net.tomp2p.storage.Data;
import java.io.IOException;
import java.util.Map;
import io.github.chronosx88.influence.contracts.observer.NetworkObserver;
import io.github.chronosx88.influence.contracts.observer.INetworkObserver;
import io.github.chronosx88.influence.helpers.actions.NetworkActions;
import io.github.chronosx88.influence.helpers.actions.UIActions;
import io.github.chronosx88.influence.models.NewChatRequestMessage;
import io.github.chronosx88.influence.models.SendMessage;
import io.github.chronosx88.influence.models.SuccessfullySentMessage;
public class NetworkHandler implements NetworkObserver {
public class NetworkHandler implements INetworkObserver {
private final static String LOG_TAG = "NetworkHandler";
private static Gson gson = new Gson();
private static PeerDHT peerDHT = AppHelper.getPeerDHT();

View File

@ -2,11 +2,11 @@ package io.github.chronosx88.influence.logic;
import java.util.List;
import io.github.chronosx88.influence.contracts.chatlist.ChatListLogicContract;
import io.github.chronosx88.influence.contracts.chatlist.IChatListLogicContract;
import io.github.chronosx88.influence.helpers.AppHelper;
import io.github.chronosx88.influence.models.roomEntities.ChatEntity;
public class ChatListLogic implements ChatListLogicContract {
public class ChatListLogic implements IChatListLogicContract {
@Override
public List<ChatEntity> loadAllChats() {

View File

@ -4,13 +4,13 @@ import com.google.gson.Gson;
import net.tomp2p.peers.PeerAddress;
import io.github.chronosx88.influence.contracts.chatactivity.ChatLogicContract;
import io.github.chronosx88.influence.contracts.chatactivity.IChatLogicContract;
import io.github.chronosx88.influence.helpers.AppHelper;
import io.github.chronosx88.influence.helpers.P2PUtils;
import io.github.chronosx88.influence.models.SendMessage;
import io.github.chronosx88.influence.models.roomEntities.MessageEntity;
public class ChatLogic implements ChatLogicContract {
public class ChatLogic implements IChatLogicContract {
private static Gson gson = new Gson();
@Override
public void sendMessage(PeerAddress address, MessageEntity message) {

View File

@ -32,7 +32,7 @@ import java.security.spec.DSAPublicKeySpec;
import java.security.spec.InvalidKeySpecException;
import java.util.UUID;
import io.github.chronosx88.influence.contracts.mainactivity.MainLogicContract;
import io.github.chronosx88.influence.contracts.mainactivity.IMainLogicContract;
import io.github.chronosx88.influence.helpers.AppHelper;
import io.github.chronosx88.influence.helpers.DSAKey;
import io.github.chronosx88.influence.helpers.KeyPairManager;
@ -42,7 +42,7 @@ import io.github.chronosx88.influence.helpers.StorageMVStore;
import io.github.chronosx88.influence.helpers.actions.UIActions;
import io.github.chronosx88.influence.models.PublicUserProfile;
public class MainLogic implements MainLogicContract {
public class MainLogic implements IMainLogicContract {
private static final String LOG_TAG = "MainLogic";
private SharedPreferences preferences;

View File

@ -3,13 +3,8 @@ package io.github.chronosx88.influence.logic;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import net.tomp2p.dht.FutureGet;
import net.tomp2p.dht.FuturePut;
import net.tomp2p.dht.PeerDHT;
import net.tomp2p.futures.FuturePing;
import net.tomp2p.peers.Number160;
import net.tomp2p.peers.Number640;
import net.tomp2p.peers.PeerAddress;
import net.tomp2p.storage.Data;
@ -18,18 +13,17 @@ import java.io.IOException;
import java.util.Map;
import java.util.UUID;
import io.github.chronosx88.influence.contracts.startchat.StartChatLogicContract;
import io.github.chronosx88.influence.contracts.startchat.IStartChatLogicContract;
import io.github.chronosx88.influence.helpers.AppHelper;
import io.github.chronosx88.influence.helpers.KeyPairManager;
import io.github.chronosx88.influence.helpers.LocalDBWrapper;
import io.github.chronosx88.influence.helpers.NetworkHandler;
import io.github.chronosx88.influence.helpers.ObservableUtils;
import io.github.chronosx88.influence.helpers.P2PUtils;
import io.github.chronosx88.influence.helpers.actions.UIActions;
import io.github.chronosx88.influence.models.NewChatRequestMessage;
import io.github.chronosx88.influence.models.PublicUserProfile;
public class StartChatLogic implements StartChatLogicContract {
public class StartChatLogic implements IStartChatLogicContract {
private PeerDHT peerDHT;
private Gson gson;
private KeyPairManager keyPairManager;

View File

@ -4,16 +4,16 @@ import com.google.gson.JsonObject;
import java.util.ArrayList;
import io.github.chronosx88.influence.contracts.observer.NetworkObserver;
import io.github.chronosx88.influence.contracts.observer.Observable;
import io.github.chronosx88.influence.contracts.observer.Observer;
import io.github.chronosx88.influence.contracts.observer.INetworkObserver;
import io.github.chronosx88.influence.contracts.observer.IObservable;
import io.github.chronosx88.influence.contracts.observer.IObserver;
public class MainObservable implements Observable {
public class MainObservable implements IObservable {
public static final int UI_ACTIONS_CHANNEL = 0;
public static final int OTHER_ACTIONS_CHANNEL = 1;
private ArrayList<Observer> uiObservers;
private ArrayList<NetworkObserver> networkObservers;
private ArrayList<IObserver> uiObservers;
private ArrayList<INetworkObserver> networkObservers;
public MainObservable() {
this.uiObservers = new ArrayList<>();
@ -21,35 +21,35 @@ public class MainObservable implements Observable {
}
@Override
public void register(Observer observer) {
public void register(IObserver observer) {
uiObservers.add(observer);
}
@Override
public void register(NetworkObserver observer) {
public void register(INetworkObserver observer) {
networkObservers.add(observer);
}
@Override
public void unregister(Observer observer) {
public void unregister(IObserver observer) {
uiObservers.remove(observer);
}
@Override
public void unregister(NetworkObserver observer) {
public void unregister(INetworkObserver observer) {
networkObservers.remove(observer);
}
@Override
public void notifyUIObservers(JsonObject jsonObject) {
for (Observer observer : uiObservers) {
for (IObserver observer : uiObservers) {
observer.handleEvent(jsonObject);
}
}
@Override
public void notifyNetworkObservers(Object object) {
for (NetworkObserver observer : networkObservers) {
for (INetworkObserver observer : networkObservers) {
observer.handleEvent(object);
}
}

View File

@ -3,12 +3,9 @@ package io.github.chronosx88.influence.presenters;
import android.content.Intent;
import android.view.MenuItem;
import net.tomp2p.dht.FutureRemove;
import net.tomp2p.peers.Number160;
import io.github.chronosx88.influence.contracts.chatlist.ChatListLogicContract;
import io.github.chronosx88.influence.contracts.chatlist.ChatListPresenterContract;
import io.github.chronosx88.influence.contracts.chatlist.ChatListViewContract;
import io.github.chronosx88.influence.contracts.chatlist.IChatListLogicContract;
import io.github.chronosx88.influence.contracts.chatlist.IChatListPresenterContract;
import io.github.chronosx88.influence.contracts.chatlist.IChatListViewContract;
import io.github.chronosx88.influence.helpers.AppHelper;
import io.github.chronosx88.influence.helpers.ChatListAdapter;
import io.github.chronosx88.influence.helpers.LocalDBWrapper;
@ -16,12 +13,12 @@ import io.github.chronosx88.influence.logic.ChatListLogic;
import io.github.chronosx88.influence.models.roomEntities.ChatEntity;
import io.github.chronosx88.influence.views.ChatActivity;
public class ChatListPresenter implements ChatListPresenterContract {
private ChatListViewContract view;
private ChatListLogicContract logic;
public class ChatListPresenter implements IChatListPresenterContract {
private IChatListViewContract view;
private IChatListLogicContract logic;
private ChatListAdapter chatListAdapter;
public ChatListPresenter(ChatListViewContract view) {
public ChatListPresenter(IChatListViewContract view) {
this.view = view;
chatListAdapter = new ChatListAdapter((v, p)-> {
openChat(chatListAdapter.getChatEntity(p).chatID);

View File

@ -8,10 +8,10 @@ import net.tomp2p.peers.PeerAddress;
import java.util.ArrayList;
import java.util.List;
import io.github.chronosx88.influence.contracts.chatactivity.ChatLogicContract;
import io.github.chronosx88.influence.contracts.chatactivity.ChatPresenterContract;
import io.github.chronosx88.influence.contracts.chatactivity.ChatViewContract;
import io.github.chronosx88.influence.contracts.observer.Observer;
import io.github.chronosx88.influence.contracts.chatactivity.IChatLogicContract;
import io.github.chronosx88.influence.contracts.chatactivity.IChatPresenterContract;
import io.github.chronosx88.influence.contracts.chatactivity.IChatViewContract;
import io.github.chronosx88.influence.contracts.observer.IObserver;
import io.github.chronosx88.influence.helpers.AppHelper;
import io.github.chronosx88.influence.helpers.LocalDBWrapper;
import io.github.chronosx88.influence.helpers.MessageTypes;
@ -20,14 +20,14 @@ import io.github.chronosx88.influence.helpers.actions.UIActions;
import io.github.chronosx88.influence.logic.ChatLogic;
import io.github.chronosx88.influence.models.roomEntities.MessageEntity;
public class ChatPresenter implements ChatPresenterContract, Observer {
private ChatLogicContract logic;
private ChatViewContract view;
public class ChatPresenter implements IChatPresenterContract, IObserver {
private IChatLogicContract logic;
private IChatViewContract view;
private PeerAddress receiverAddress;
private String chatID;
private Gson gson;
public ChatPresenter(ChatViewContract view, String chatID) {
public ChatPresenter(IChatViewContract view, String chatID) {
this.logic = new ChatLogic();
this.view = view;
this.chatID = chatID;

View File

@ -1,15 +1,15 @@
package io.github.chronosx88.influence.presenters;
import io.github.chronosx88.influence.contracts.mainactivity.MainLogicContract;
import io.github.chronosx88.influence.contracts.mainactivity.MainPresenterContract;
import io.github.chronosx88.influence.contracts.mainactivity.MainViewContract;
import io.github.chronosx88.influence.contracts.mainactivity.IMainLogicContract;
import io.github.chronosx88.influence.contracts.mainactivity.IMainPresenterContract;
import io.github.chronosx88.influence.contracts.mainactivity.IMainViewContract;
import io.github.chronosx88.influence.logic.MainLogic;
public class MainPresenter implements MainPresenterContract {
private MainLogicContract logic;
private MainViewContract view;
public class MainPresenter implements IMainPresenterContract {
private IMainLogicContract logic;
private IMainViewContract view;
public MainPresenter(MainViewContract view) {
public MainPresenter(IMainViewContract view) {
this.view = view;
logic = new MainLogic();
}

View File

@ -2,19 +2,19 @@ package io.github.chronosx88.influence.presenters;
import com.google.gson.JsonObject;
import io.github.chronosx88.influence.contracts.observer.Observer;
import io.github.chronosx88.influence.contracts.startchat.StartChatLogicContract;
import io.github.chronosx88.influence.contracts.startchat.StartChatPresenterContract;
import io.github.chronosx88.influence.contracts.startchat.StartChatViewContract;
import io.github.chronosx88.influence.contracts.observer.IObserver;
import io.github.chronosx88.influence.contracts.startchat.IStartChatLogicContract;
import io.github.chronosx88.influence.contracts.startchat.IStartChatPresenterContract;
import io.github.chronosx88.influence.contracts.startchat.IStartChatViewContract;
import io.github.chronosx88.influence.helpers.AppHelper;
import io.github.chronosx88.influence.helpers.actions.UIActions;
import io.github.chronosx88.influence.logic.StartChatLogic;
public class StartChatPresenter implements StartChatPresenterContract, Observer {
private StartChatViewContract view;
private StartChatLogicContract logic;
public class StartChatPresenter implements IStartChatPresenterContract, IObserver {
private IStartChatViewContract view;
private IStartChatLogicContract logic;
public StartChatPresenter(StartChatViewContract view) {
public StartChatPresenter(IStartChatViewContract view) {
this.view = view;
this.logic = new StartChatLogic();
AppHelper.getObservable().register(this);

View File

@ -14,12 +14,12 @@ import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import io.github.chronosx88.influence.R;
import io.github.chronosx88.influence.contracts.chatactivity.ChatViewContract;
import io.github.chronosx88.influence.contracts.chatactivity.IChatViewContract;
import io.github.chronosx88.influence.helpers.ChatAdapter;
import io.github.chronosx88.influence.models.roomEntities.MessageEntity;
import io.github.chronosx88.influence.presenters.ChatPresenter;
public class ChatActivity extends AppCompatActivity implements ChatViewContract {
public class ChatActivity extends AppCompatActivity implements IChatViewContract {
private ChatAdapter chatAdapter;
private RecyclerView messageList;
private ImageButton sendMessageButton;

View File

@ -13,9 +13,9 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import io.github.chronosx88.influence.R;
import io.github.chronosx88.influence.contracts.mainactivity.MainPresenterContract;
import io.github.chronosx88.influence.contracts.mainactivity.MainViewContract;
import io.github.chronosx88.influence.contracts.observer.Observer;
import io.github.chronosx88.influence.contracts.mainactivity.IMainPresenterContract;
import io.github.chronosx88.influence.contracts.mainactivity.IMainViewContract;
import io.github.chronosx88.influence.contracts.observer.IObserver;
import io.github.chronosx88.influence.helpers.AppHelper;
import io.github.chronosx88.influence.helpers.actions.UIActions;
import io.github.chronosx88.influence.presenters.MainPresenter;
@ -23,9 +23,9 @@ import io.github.chronosx88.influence.views.fragments.ChatListFragment;
import io.github.chronosx88.influence.views.fragments.SettingsFragment;
import io.github.chronosx88.influence.views.fragments.StartChatFragment;
public class MainActivity extends AppCompatActivity implements Observer, MainViewContract {
public class MainActivity extends AppCompatActivity implements IObserver, IMainViewContract {
private MainPresenterContract presenter;
private IMainPresenterContract presenter;
private ProgressDialog progressDialog;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {

View File

@ -17,17 +17,17 @@ import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import io.github.chronosx88.influence.R;
import io.github.chronosx88.influence.contracts.chatlist.ChatListPresenterContract;
import io.github.chronosx88.influence.contracts.chatlist.ChatListViewContract;
import io.github.chronosx88.influence.contracts.observer.Observer;
import io.github.chronosx88.influence.contracts.chatlist.IChatListPresenterContract;
import io.github.chronosx88.influence.contracts.chatlist.IChatListViewContract;
import io.github.chronosx88.influence.contracts.observer.IObserver;
import io.github.chronosx88.influence.helpers.AppHelper;
import io.github.chronosx88.influence.helpers.ChatListAdapter;
import io.github.chronosx88.influence.helpers.actions.UIActions;
import io.github.chronosx88.influence.models.roomEntities.ChatEntity;
import io.github.chronosx88.influence.presenters.ChatListPresenter;
public class ChatListFragment extends Fragment implements ChatListViewContract, Observer {
private ChatListPresenterContract presenter;
public class ChatListFragment extends Fragment implements IChatListViewContract, IObserver {
private IChatListPresenterContract presenter;
private RecyclerView chatList;
private Handler mainThreadHandler;

View File

@ -3,7 +3,6 @@ package io.github.chronosx88.influence.views.fragments;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -17,10 +16,10 @@ import androidx.annotation.Nullable;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment;
import io.github.chronosx88.influence.R;
import io.github.chronosx88.influence.contracts.startchat.StartChatViewContract;
import io.github.chronosx88.influence.contracts.startchat.IStartChatViewContract;
import io.github.chronosx88.influence.presenters.StartChatPresenter;
public class StartChatFragment extends Fragment implements StartChatViewContract {
public class StartChatFragment extends Fragment implements IStartChatViewContract {
private TextInputLayout textInputPeerID;
private ProgressDialog progressDialog;
private Button createChatButton;