mvp: Introducing Model View Presenter pattern
libringclient is a new module where we will put avery non Android code.
MVP must not depend on Android.
app now depends on that module. It should improve reusability.
Change-Id: I20c7d7adeed43212a21e5e617e6d2b6054db8a40
Tuleap: #1217
diff --git a/ring-android/libringclient/.gitignore b/ring-android/libringclient/.gitignore
new file mode 100644
index 0000000..796b96d
--- /dev/null
+++ b/ring-android/libringclient/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/ring-android/libringclient/build.gradle b/ring-android/libringclient/build.gradle
new file mode 100644
index 0000000..49df001
--- /dev/null
+++ b/ring-android/libringclient/build.gradle
@@ -0,0 +1,8 @@
+apply plugin: 'java'
+
+dependencies {
+ compile fileTree(dir: 'libs', include: ['*.jar'])
+}
+
+sourceCompatibility = "1.7"
+targetCompatibility = "1.7"
diff --git a/ring-android/libringclient/src/main/java/cx/ring/mvp/RootPresenter.java b/ring-android/libringclient/src/main/java/cx/ring/mvp/RootPresenter.java
new file mode 100644
index 0000000..f3cd758
--- /dev/null
+++ b/ring-android/libringclient/src/main/java/cx/ring/mvp/RootPresenter.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2016 Savoir-faire Linux Inc.
+ *
+ * Author: Thibault Wittemberg <thibault.wittemberg@savoirfairelinux.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package cx.ring.mvp;
+
+import java.lang.ref.WeakReference;
+
+public class RootPresenter<T> {
+
+ private WeakReference<T> mView;
+
+ public void bindView(T view) {
+ mView = new WeakReference<>(view);
+ }
+
+ public void unbindView() {
+ if (mView != null) {
+ mView.clear();
+ }
+
+ mView = null;
+ }
+
+ public T getView() {
+ if (mView != null) {
+ return mView.get();
+ }
+
+ return null;
+ }
+
+}
+
+