Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

Commit

Permalink
replace kotlin Pair and Triple
Browse files Browse the repository at this point in the history
  • Loading branch information
Guiorgy committed Jun 12, 2019
1 parent 8a3fc8e commit 7862afa
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

import com.obsez.android.lib.smbfilechooser.internals.ExtSmbFileFilter;
import com.obsez.android.lib.smbfilechooser.internals.RegexSmbFileFilter;
import com.obsez.android.lib.smbfilechooser.internals.Triple;
import com.obsez.android.lib.smbfilechooser.internals.UiUtil;
import com.obsez.android.lib.smbfilechooser.permissions.PermissionsUtil;
import com.obsez.android.lib.smbfilechooser.tool.IExceptionHandler;
Expand Down Expand Up @@ -74,7 +75,6 @@
import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileFilter;
import kotlin.Triple;

import static android.view.Gravity.BOTTOM;
import static android.view.Gravity.CENTER;
Expand Down Expand Up @@ -1655,15 +1655,15 @@ public void onItemClick(@Nullable final AdapterView<?> parent, @NonNull final Vi
_chooseMode = _chooseMode == CHOOSE_MODE_DELETE ? CHOOSE_MODE_NORMAL : _chooseMode;
if (_deleteMode != null) _deleteMode.run();
lastSelected = _adapter.isEmpty();
return new Triple<SmbFile, Boolean, String>(file, true, null);
return new Triple<SmbFile, Boolean, String>(file, true);
}
}
return new Triple<>(file, file.isDirectory(), file.getPath());
}).get();

final SmbFile file = triple.getFirst();
final boolean isDirectory = triple.getSecond();
final String path = triple.getThird();
final SmbFile file = triple.first;
final boolean isDirectory = triple.second;
final String path = triple.third;
int scrollTo = 0;

if (file != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.obsez.android.lib.smbfilechooser.internals;

import android.util.Pair;

public class Triple<F, S, T> extends Pair<F, S> {
public final T third;

/**
* Constructor for a Pair.
*
* @param first the first object in the Pair
* @param second the second object in the pair
*/
public Triple(F first, S second) {
this(first, second, null);
}

/**
* Constructor for a Triple.
*
* @param first the first object in the Triple
* @param second the second object in the Triple
* @param third the third object in the Triple
*/
public Triple(F first, S second, T third) {
super(first, second);
this.third = third;
}

protected static boolean nullSafeEquals(Object a, Object b) {
//noinspection EqualsReplaceableByObjectsCall
return (a == b) || (a != null && a.equals(b));
}

@Override
public boolean equals(Object o) {
return (o instanceof Triple && nullSafeEquals(((Triple) o).first, first) && nullSafeEquals(((Triple) o).second, second) && nullSafeEquals(((Triple) o).third, third));
}

@Override
public int hashCode() {
return super.hashCode() ^ (third == null ? 0 : third.hashCode());
}

@Override
public String toString() {
return "Triple{" + first + ", " + second + ", " + third + "}";
}

/**
* @deprecated use {@link #create(Object, Object, Object)} instead
*/
@Deprecated
public static <A, B> Pair <A, B> create(A a, B b) {
throw new UnsupportedOperationException();
}

/**
* Convenience method for creating an appropriately typed Triple.
* @param a the first object in the Triple
* @param b the second object in the Triple
* @param c the third object in the Triple
* @return a Triple that is templatized with the types of a, b and c
*/
public static <A, B, C> Triple <A, B, C> create(A a, B b, C c) {
return new Triple<>(a, b, c);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -22,7 +23,6 @@

import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;
import kotlin.Pair;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;
Expand Down Expand Up @@ -148,11 +148,11 @@ protected Void doInBackground(final SmbFile... files) {
protected final void onProgressUpdate(Pair<Integer, FileInfo>... pairs) {
if (isCancelled()) return;
Pair<Integer, FileInfo> pair = pairs[0];
this.files.append(pair.getFirst(), pair.getSecond());
Pair<View, Boolean> view = this.views.get(pair.getFirst(), null);
this.files.append(pair.first, pair.second);
Pair<View, Boolean> view = this.views.get(pair.first, null);
if (view != null) {
this.views.remove(pair.getFirst());
bindView(view.getFirst(), pair.getSecond(), view.getSecond());
this.views.remove(pair.first);
bindView(view.first, pair.second, view.second);
}
}

Expand All @@ -165,7 +165,7 @@ protected void onPostExecute(Void aVoid) {
if (file == null) continue;
Pair<View, Boolean> pair = this.views.get(hashCode, null);
if (pair == null) continue;
bindView(pair.getFirst(), file, pair.getSecond());
bindView(pair.first, file, pair.second);
}
adapter.notifyDataSetChanged();
}
Expand Down

0 comments on commit 7862afa

Please sign in to comment.