aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/net/lacolaco/smileessence/view/adapter
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/net/lacolaco/smileessence/view/adapter')
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/adapter/CustomListAdapter.java50
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/adapter/CustomListAdapter.kt45
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/adapter/EventListAdapter.java116
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/adapter/EventListAdapter.kt102
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/adapter/MessageListAdapter.kt (renamed from app/src/main/java/net/lacolaco/smileessence/view/adapter/MessageListAdapter.java)36
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/adapter/OrderedCustomListAdapter.java41
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/adapter/OrderedCustomListAdapter.kt35
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/adapter/PageListAdapter.java140
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/adapter/PageListAdapter.kt110
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/adapter/TimelineAdapter.java39
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/adapter/TimelineAdapter.kt29
11 files changed, 334 insertions, 409 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/adapter/CustomListAdapter.java b/app/src/main/java/net/lacolaco/smileessence/view/adapter/CustomListAdapter.java
deleted file mode 100644
index 6d7420fb..00000000
--- a/app/src/main/java/net/lacolaco/smileessence/view/adapter/CustomListAdapter.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package net.lacolaco.smileessence.view.adapter;
-
-import android.widget.BaseAdapter;
-import net.lacolaco.smileessence.util.UIHandler;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-public abstract class CustomListAdapter<T> extends BaseAdapter {
- private boolean isNotifiable = true;
- private List<T> frozenList = new ArrayList<>();
-
- public final void setNotifiable(boolean notifiable) {
- isNotifiable = notifiable;
- }
-
- @Override
- public final int getCount() {
- return frozenList.size();
- }
-
- @Override
- public final T getItem(int position) {
- return frozenList.get(position);
- }
-
- @Override
- public long getItemId(int position) {
- return position;
- }
-
- @Override
- public final void notifyDataSetChanged() {
- frozenList = Collections.unmodifiableList(getList());
- super.notifyDataSetChanged();
- }
-
- protected abstract List<T> getList();
-
- public void update() {
- if (isNotifiable) {
- updateForce();
- }
- }
-
- public void updateForce() {
- new UIHandler().post(this::notifyDataSetChanged);
- }
-} \ No newline at end of file
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/adapter/CustomListAdapter.kt b/app/src/main/java/net/lacolaco/smileessence/view/adapter/CustomListAdapter.kt
new file mode 100644
index 00000000..3b022012
--- /dev/null
+++ b/app/src/main/java/net/lacolaco/smileessence/view/adapter/CustomListAdapter.kt
@@ -0,0 +1,45 @@
+package net.lacolaco.smileessence.view.adapter
+
+import android.widget.BaseAdapter
+import net.lacolaco.smileessence.util.UIHandler
+
+import java.util.ArrayList
+import java.util.Collections
+
+abstract class CustomListAdapter<T> : BaseAdapter() {
+ private var isNotifiable = true
+ private var frozenList: List<T> = ArrayList()
+
+ fun setNotifiable(notifiable: Boolean) {
+ isNotifiable = notifiable
+ }
+
+ override fun getCount(): Int {
+ return frozenList.size
+ }
+
+ override fun getItem(position: Int): T {
+ return frozenList[position]
+ }
+
+ override fun getItemId(position: Int): Long {
+ return position.toLong()
+ }
+
+ override fun notifyDataSetChanged() {
+ frozenList = Collections.unmodifiableList(list)
+ super.notifyDataSetChanged()
+ }
+
+ protected abstract val list: List<T>
+
+ fun update() {
+ if (isNotifiable) {
+ updateForce()
+ }
+ }
+
+ fun updateForce() {
+ UIHandler().post { this.notifyDataSetChanged() }
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/adapter/EventListAdapter.java b/app/src/main/java/net/lacolaco/smileessence/view/adapter/EventListAdapter.java
deleted file mode 100644
index 3f98cfaa..00000000
--- a/app/src/main/java/net/lacolaco/smileessence/view/adapter/EventListAdapter.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2012-2014 lacolaco.net
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package net.lacolaco.smileessence.view.adapter;
-
-import android.app.Activity;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ImageView;
-import android.widget.TextView;
-import com.android.volley.toolbox.NetworkImageView;
-import net.lacolaco.smileessence.R;
-import net.lacolaco.smileessence.World;
-import net.lacolaco.smileessence.data.ImageCache;
-import net.lacolaco.smileessence.entity.Event;
-import net.lacolaco.smileessence.entity.RBinding;
-import net.lacolaco.smileessence.preference.UserPreferenceHelper;
-import net.lacolaco.smileessence.util.StringUtils;
-import net.lacolaco.smileessence.util.UIObserverBundle;
-import net.lacolaco.smileessence.view.DialogHelper;
-import net.lacolaco.smileessence.view.dialog.UserDetailDialogFragment;
-import net.lacolaco.smileessence.view.listener.ListItemClickListener;
-
-import java.lang.ref.WeakReference;
-import java.util.List;
-
-public class EventListAdapter extends CustomListAdapter<Event> {
- private final World world;
- private final Activity activity;
-
- public EventListAdapter(World world, Activity activity) {
- super();
- this.world = world;
- this.activity = activity;
- }
-
- @Override
- protected List<Event> getList() {
- return world.getEvents();
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- Event event = getItem(position);
- if (convertView == null) {
- convertView = activity.getLayoutInflater().inflate(R.layout.list_item_status, null);
- }
- UIObserverBundle bundle = (UIObserverBundle) convertView.getTag();
- if (bundle != null) {
- bundle.detachAll();
- } else {
- bundle = new UIObserverBundle();
- convertView.setTag(bundle);
- }
-
- int textSize = UserPreferenceHelper.getInstance().getTextSize();
-
- TextView header = (TextView) convertView.findViewById(R.id.textview_status_header);
- header.setTextSize(textSize);
-
- updateViewUser(event, convertView);
-
- TextView content = (TextView) convertView.findViewById(R.id.textview_status_text);
- content.setTextSize(textSize);
- content.setText(event.getTargetObject() != null ? event.getTargetObject().getText() : "");
- TextView footer = (TextView) convertView.findViewById(R.id.textview_status_footer);
- footer.setTextSize(textSize - 2);
- footer.setText(StringUtils.dateToString(event.getCreatedAt()));
- ImageView favorited = (ImageView) convertView.findViewById(R.id.imageview_status_favorited);
- favorited.setVisibility(View.GONE);
- convertView.setOnClickListener(new ListItemClickListener(activity, () -> {
- UserDetailDialogFragment fragment = new UserDetailDialogFragment();
- fragment.setUserID(event.getSource().getId());
- DialogHelper.showDialog(activity, fragment);
- }));
-
- final WeakReference<View> weakView = new WeakReference<>(convertView);
- bundle.attach(event.getSource(), changes -> {
- View strongView = weakView.get();
- if (strongView != null && changes.contains(RBinding.BASIC))
- updateViewUser(event, strongView);
- });
-
- return convertView;
- }
-
- private void updateViewUser(Event event, View convertedView) {
- NetworkImageView icon = (NetworkImageView) convertedView.findViewById(R.id.imageview_status_icon);
- String iconUrl = event.getSource().getProfileImageUrlOriginal();
- icon.setImageUrl(iconUrl, ImageCache.getImageLoader());
-
- TextView header = (TextView) convertedView.findViewById(R.id.textview_status_header);
- header.setText(event.getFormattedString());
- }
-}
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/adapter/EventListAdapter.kt b/app/src/main/java/net/lacolaco/smileessence/view/adapter/EventListAdapter.kt
new file mode 100644
index 00000000..1c19d4ec
--- /dev/null
+++ b/app/src/main/java/net/lacolaco/smileessence/view/adapter/EventListAdapter.kt
@@ -0,0 +1,102 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2012-2014 lacolaco.net
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.lacolaco.smileessence.view.adapter
+
+import android.app.Activity
+import android.view.View
+import android.view.ViewGroup
+import android.widget.ImageView
+import android.widget.TextView
+import com.android.volley.toolbox.NetworkImageView
+import net.lacolaco.smileessence.R
+import net.lacolaco.smileessence.World
+import net.lacolaco.smileessence.data.ImageCache
+import net.lacolaco.smileessence.entity.Event
+import net.lacolaco.smileessence.entity.RBinding
+import net.lacolaco.smileessence.preference.UserPreferenceHelper
+import net.lacolaco.smileessence.util.StringUtils
+import net.lacolaco.smileessence.util.UIObserverBundle
+import net.lacolaco.smileessence.view.DialogHelper
+import net.lacolaco.smileessence.view.dialog.UserDetailDialogFragment
+import net.lacolaco.smileessence.view.listener.ListItemClickListener
+
+import java.lang.ref.WeakReference
+
+class EventListAdapter(private val world: World, private val activity: Activity) : CustomListAdapter<Event>() {
+ override val list: List<Event>
+ get() = world.events
+
+ override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
+ var convertView = convertView
+ val event = getItem(position)
+ if (convertView == null) {
+ convertView = activity.layoutInflater.inflate(R.layout.list_item_status, null)
+ }
+ var bundle: UIObserverBundle? = convertView!!.tag as UIObserverBundle?
+ if (bundle != null) {
+ bundle.detachAll()
+ } else {
+ bundle = UIObserverBundle()
+ convertView.tag = bundle
+ }
+
+ val textSize = UserPreferenceHelper.instance.textSize
+
+ val header = convertView.findViewById(R.id.textview_status_header) as TextView
+ header.textSize = textSize.toFloat()
+
+ updateViewUser(event, convertView)
+
+ val content = convertView.findViewById(R.id.textview_status_text) as TextView
+ content.textSize = textSize.toFloat()
+ content.text = event.targetObject?.text ?: ""
+ val footer = convertView.findViewById(R.id.textview_status_footer) as TextView
+ footer.textSize = (textSize - 2).toFloat()
+ footer.text = StringUtils.dateToString(event.createdAt)
+ val favorited = convertView.findViewById(R.id.imageview_status_favorited) as ImageView
+ favorited.visibility = View.GONE
+ convertView.setOnClickListener(ListItemClickListener(activity) {
+ DialogHelper.showDialog(activity, UserDetailDialogFragment.newInstance(event.source))
+ })
+
+ val weakView = WeakReference(convertView)
+ bundle.attach(event.source) { changes ->
+ val strongView = weakView.get()
+ if (strongView != null && changes.contains(RBinding.BASIC))
+ updateViewUser(event, strongView)
+ }
+
+ return convertView
+ }
+
+ private fun updateViewUser(event: Event, convertedView: View) {
+ val icon = convertedView.findViewById(R.id.imageview_status_icon) as NetworkImageView
+ val iconUrl = event.source.profileImageUrl
+ icon.setImageUrl(iconUrl, ImageCache.getImageLoader())
+
+ val header = convertedView.findViewById(R.id.textview_status_header) as TextView
+ header.text = event.formattedString
+ }
+}
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/adapter/MessageListAdapter.java b/app/src/main/java/net/lacolaco/smileessence/view/adapter/MessageListAdapter.kt
index 9f8e5039..d72ab564 100644
--- a/app/src/main/java/net/lacolaco/smileessence/view/adapter/MessageListAdapter.java
+++ b/app/src/main/java/net/lacolaco/smileessence/view/adapter/MessageListAdapter.kt
@@ -22,32 +22,22 @@
* SOFTWARE.
*/
-package net.lacolaco.smileessence.view.adapter;
+package net.lacolaco.smileessence.view.adapter
-import android.app.Activity;
-import android.view.View;
-import android.view.ViewGroup;
-import net.lacolaco.smileessence.entity.DirectMessage;
-import net.lacolaco.smileessence.view.Partials;
+import android.app.Activity
+import android.view.View
+import android.view.ViewGroup
+import net.lacolaco.smileessence.entity.DirectMessage
+import net.lacolaco.smileessence.view.Partials
-public class MessageListAdapter extends OrderedCustomListAdapter<DirectMessage> {
- private final Activity activity;
+class MessageListAdapter(private val activity: Activity) : OrderedCustomListAdapter<DirectMessage>() {
+ val lastID: Long
+ get() = if (count > 0) getItem(count - 1).id else -1
- public MessageListAdapter(Activity activity) {
- super();
- this.activity = activity;
- }
-
- public long getLastID() {
- return getCount() > 0 ? getItem(getCount() - 1).getId() : -1;
- }
-
- public long getTopID() {
- return getCount() > 0 ? getItem(0).getId() : -1;
- }
+ val topID: Long
+ get() = if (count > 0) getItem(0).id else -1
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- return Partials.getDirectMessageView(getItem(position), activity, convertView);
+ override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
+ return Partials.getDirectMessageView(getItem(position), activity, convertView)
}
}
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/adapter/OrderedCustomListAdapter.java b/app/src/main/java/net/lacolaco/smileessence/view/adapter/OrderedCustomListAdapter.java
deleted file mode 100644
index 3de58658..00000000
--- a/app/src/main/java/net/lacolaco/smileessence/view/adapter/OrderedCustomListAdapter.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package net.lacolaco.smileessence.view.adapter;
-
-import net.lacolaco.smileessence.entity.IdObject;
-
-import java.util.*;
-
-public abstract class OrderedCustomListAdapter<T extends IdObject> extends CustomListAdapter<T> {
- private final Map<Long, T> treeMap;
-
- public OrderedCustomListAdapter() {
- this(Long::compare);
- }
-
- public OrderedCustomListAdapter(Comparator<Long> comparator) {
- super();
- this.treeMap = new TreeMap<>(Collections.reverseOrder(comparator));
- }
-
- @Override
- protected synchronized List<T> getList() {
- return new ArrayList<>(treeMap.values());
- }
-
- public synchronized void add(T item) {
- treeMap.put(item.getId(), item);
- }
-
- public synchronized void addAll(Collection<T> items) {
- for (T item : items) {
- treeMap.put(item.getId(), item);
- }
- }
-
- public synchronized void clear() {
- treeMap.clear();
- }
-
- public synchronized T remove(T item) {
- return treeMap.remove(item.getId());
- }
-}
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/adapter/OrderedCustomListAdapter.kt b/app/src/main/java/net/lacolaco/smileessence/view/adapter/OrderedCustomListAdapter.kt
new file mode 100644
index 00000000..53b1c824
--- /dev/null
+++ b/app/src/main/java/net/lacolaco/smileessence/view/adapter/OrderedCustomListAdapter.kt
@@ -0,0 +1,35 @@
+package net.lacolaco.smileessence.view.adapter
+
+import net.lacolaco.smileessence.entity.IdObject
+
+import java.util.*
+
+abstract class OrderedCustomListAdapter<T : IdObject>
+constructor(comparator: Comparator<Long> = Comparator { x, y -> java.lang.Long.compare(x, y) }) : CustomListAdapter<T>() {
+ private val treeMap: MutableMap<Long, T> = TreeMap(Collections.reverseOrder(comparator))
+
+ override val list: List<T>
+ @Synchronized get() = ArrayList(treeMap.values)
+
+ @Synchronized
+ fun add(item: T) {
+ treeMap.put(item.id, item)
+ }
+
+ @Synchronized
+ fun addAll(items: Collection<T>) {
+ for (item in items) {
+ treeMap.put(item.id, item)
+ }
+ }
+
+ @Synchronized
+ fun clear() {
+ treeMap.clear()
+ }
+
+ @Synchronized
+ fun remove(item: T): T {
+ return treeMap.remove(item.id)!!
+ }
+}
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/adapter/PageListAdapter.java b/app/src/main/java/net/lacolaco/smileessence/view/adapter/PageListAdapter.java
deleted file mode 100644
index 76e72093..00000000
--- a/app/src/main/java/net/lacolaco/smileessence/view/adapter/PageListAdapter.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2012-2014 lacolaco.net
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package net.lacolaco.smileessence.view.adapter;
-
-import android.os.Bundle;
-import android.support.v13.app.FragmentPagerAdapter;
-import net.lacolaco.smileessence.activity.MainActivity;
-import net.lacolaco.smileessence.logging.Logger;
-import net.lacolaco.smileessence.view.page.PageFragment;
-
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class PageListAdapter extends FragmentPagerAdapter {
-
- // ------------------------------ FIELDS ------------------------------
-
- private final List<PageInfo> pages = new ArrayList<>();
- private final Map<Integer, WeakReference<PageFragment>> fragmentCache = new HashMap<>();
-
- // --------------------------- FragmentPagerAdapter ---------------------------
-
- public PageListAdapter(MainActivity _activity) {
- super(_activity.getFragmentManager());
- }
-
- @Override
- public synchronized PageFragment getItem(int position) {
- PageFragment pf;
- PageInfo info = pages.get(position);
- try {
- pf = info.getFragmentClass().newInstance();
- } catch (Exception e) {
- Logger.error("should not happen: fragmentClass is private or Android is broken?");
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- pf.setArguments(info.getArgs());
- fragmentCache.put(position, new WeakReference<>(pf));
- return pf;
- }
-
- public synchronized PageFragment getCachedFragment(int pos) {
- WeakReference<PageFragment> wpf = fragmentCache.get(pos);
- if (wpf == null) {
- return null;
- } else {
- return wpf.get();
- }
- }
-
- @Override
- public synchronized int getCount() {
- return pages.size();
- }
-
- // ------------------------ INTERFACE METHODS ------------------------
-
- // -------------------------- OTHER METHODS --------------------------
-
- public void addPage(Class<? extends PageFragment> klass, String name, Bundle args) {
- this.addPage(klass, name, args, true);
- }
-
- public void addPage(Class<? extends PageFragment> klass, String name, Bundle args, boolean notifyChanged) {
- pages.add(new PageInfo(klass, name, args));
- if (notifyChanged) notifyDataSetChanged();
- }
-
- public synchronized boolean removePage(int position) {
- //if (removePageWithoutNotify(position)) {
- // refreshListNavigation();
- // return true;
- //}
- return pages.remove(position) != null; // TODO
- }
-
- public String getName(int pos) {
- return pages.get(pos).getName();
- }
-
- @Deprecated
- public int getIndex(Class<? extends PageFragment> fragmentClass) {
- for (int i = 0; i < pages.size(); ++i) {
- if (pages.get(i).getFragmentClass() == fragmentClass) {
- return i;
- }
- }
- return -1;
- }
-
- private static final class PageInfo {
- private final Class<? extends PageFragment> fragmentClass;
- private final Bundle args;
- private final String name;
-
- PageInfo(Class<? extends PageFragment> _fragmentClass, String _name, Bundle _args) {
- fragmentClass = _fragmentClass;
- name = _name;
- args = _args;
- }
-
- public Class<? extends PageFragment> getFragmentClass() {
- return fragmentClass;
- }
-
- public String getName() {
- return name;
- }
-
- public Bundle getArgs() {
- return args;
- }
- }
-}
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/adapter/PageListAdapter.kt b/app/src/main/java/net/lacolaco/smileessence/view/adapter/PageListAdapter.kt
new file mode 100644
index 00000000..34d158f0
--- /dev/null
+++ b/app/src/main/java/net/lacolaco/smileessence/view/adapter/PageListAdapter.kt
@@ -0,0 +1,110 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2012-2014 lacolaco.net
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.lacolaco.smileessence.view.adapter
+
+import android.os.Bundle
+import android.support.v13.app.FragmentPagerAdapter
+import net.lacolaco.smileessence.activity.MainActivity
+import net.lacolaco.smileessence.logging.Logger
+import net.lacolaco.smileessence.view.page.PageFragment
+
+import java.lang.ref.WeakReference
+import java.util.ArrayList
+import java.util.HashMap
+
+class PageListAdapter
+// --------------------------- FragmentPagerAdapter ---------------------------
+
+(_activity: MainActivity) : FragmentPagerAdapter(_activity.fragmentManager) {
+
+ // ------------------------------ FIELDS ------------------------------
+
+ private val pages = ArrayList<PageInfo>()
+ private val fragmentCache = HashMap<Int, WeakReference<PageFragment<*>>>()
+
+ @Synchronized override fun getItem(position: Int): PageFragment<*> {
+ val pf: PageFragment<*>
+ val info = pages[position]
+ try {
+ pf = info.fragmentClass.newInstance()
+ } catch (e: Exception) {
+ Logger.error("should not happen: fragmentClass is private or Android is broken?")
+ e.printStackTrace()
+ throw RuntimeException(e)
+ }
+
+ pf.arguments = info.args
+ fragmentCache.put(position, WeakReference(pf))
+ return pf
+ }
+
+ @Synchronized
+ fun getCachedFragment(pos: Int): PageFragment<*>? {
+ val wpf = fragmentCache[pos]
+ return wpf?.get()
+ }
+
+ @Synchronized override fun getCount(): Int {
+ return pages.size
+ }
+
+ // ------------------------ INTERFACE METHODS ------------------------
+
+ // -------------------------- OTHER METHODS --------------------------
+
+ fun addPage(klass: Class<out PageFragment<*>>, name: String, args: Bundle) {
+ this.addPage(klass, name, args, true)
+ }
+
+ fun addPage(klass: Class<out PageFragment<*>>, name: String, args: Bundle, notifyChanged: Boolean) {
+ pages.add(PageInfo(klass, name, args))
+ if (notifyChanged) notifyDataSetChanged()
+ }
+
+ @Synchronized
+ fun removePage(position: Int): Boolean {
+ //if (removePageWithoutNotify(position)) {
+ // refreshListNavigation();
+ // return true;
+ //}
+ return pages.removeAt(position) != null // TODO
+ }
+
+ fun getName(pos: Int): String {
+ return pages[pos].name
+ }
+
+ @Deprecated("")
+ fun getIndex(fragmentClass: Class<out PageFragment<*>>): Int {
+ for (i in pages.indices) {
+ if (pages[i].fragmentClass == fragmentClass) {
+ return i
+ }
+ }
+ return -1
+ }
+
+ private class PageInfo internal constructor(val fragmentClass: Class<out PageFragment<*>>, val name: String, val args: Bundle)
+}
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/adapter/TimelineAdapter.java b/app/src/main/java/net/lacolaco/smileessence/view/adapter/TimelineAdapter.java
deleted file mode 100644
index 0dbe8d53..00000000
--- a/app/src/main/java/net/lacolaco/smileessence/view/adapter/TimelineAdapter.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package net.lacolaco.smileessence.view.adapter;
-
-import android.app.Activity;
-import android.view.View;
-import android.view.ViewGroup;
-import net.lacolaco.smileessence.entity.Tweet;
-import net.lacolaco.smileessence.view.Partials;
-
-import java.util.*;
-
-public class TimelineAdapter extends OrderedCustomListAdapter<Tweet> {
- private final Activity activity;
-
- public TimelineAdapter(Activity activity) {
- super();
- this.activity = activity;
- }
-
- public long getLastID() {
- if (getCount() > 0) {
- return getItem(getCount() - 1).getId();
- } else {
- return -1;
- }
- }
-
- public long getTopID() {
- if (getCount() > 0) {
- return getItem(0).getId();
- } else {
- return -1;
- }
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- return Partials.getTweetView(getItem(position), activity, convertView, true);
- }
-}
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/adapter/TimelineAdapter.kt b/app/src/main/java/net/lacolaco/smileessence/view/adapter/TimelineAdapter.kt
new file mode 100644
index 00000000..750b63a0
--- /dev/null
+++ b/app/src/main/java/net/lacolaco/smileessence/view/adapter/TimelineAdapter.kt
@@ -0,0 +1,29 @@
+package net.lacolaco.smileessence.view.adapter
+
+import android.app.Activity
+import android.view.View
+import android.view.ViewGroup
+import net.lacolaco.smileessence.entity.Tweet
+import net.lacolaco.smileessence.view.Partials
+
+import java.util.*
+
+class TimelineAdapter(private val activity: Activity) : OrderedCustomListAdapter<Tweet>() {
+ val lastID: Long
+ get() = if (count > 0) {
+ getItem(count - 1).id
+ } else {
+ -1
+ }
+
+ val topID: Long
+ get() = if (count > 0) {
+ getItem(0).id
+ } else {
+ -1
+ }
+
+ override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
+ return Partials.getTweetView(getItem(position), activity, convertView, true)
+ }
+}