Skip to content

Commit

Permalink
use library, remove mock data
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Dec 16, 2024
1 parent 1e68bf0 commit dce1b61
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 73 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/nextcloud/client/NominatimClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.google.gson.annotations.SerializedName
import com.owncloud.android.MainApp
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.internal.http.HTTP_OK
import java.net.HttpURLConnection.HTTP_OK
import java.net.URLEncoder

class NominatimClient constructor(geocoderBaseUrl: String, email: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

import com.elyeproj.loaderviewlibrary.LoaderImageView;
import com.nextcloud.android.common.ui.theme.utils.ColorRole;
import com.nextcloud.android.lib.resources.recommendations.GetRecommendationsRemoteOperation;
import com.nextcloud.android.lib.resources.recommendations.Recommendation;
import com.nextcloud.client.account.User;
import com.nextcloud.client.database.entity.OfflineOperationEntity;
import com.nextcloud.client.jobs.upload.FileUploadHelper;
Expand Down Expand Up @@ -82,7 +84,6 @@
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -145,6 +146,8 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
private final long headerId = UUID.randomUUID().getLeastSignificantBits();
private final SyncedFolderProvider syncedFolderProvider;

private final ArrayList<Recommendation> recommendedFiles;

public OCFileListAdapter(
Activity activity,
@NonNull User user,
Expand All @@ -154,7 +157,9 @@ public OCFileListAdapter(
OCFileListFragmentInterface ocFileListFragmentInterface,
boolean argHideItemOptions,
boolean gridView,
final ViewThemeUtils viewThemeUtils) {
final ViewThemeUtils viewThemeUtils,
final ArrayList<Recommendation> recommendedFiles) {
this.recommendedFiles = recommendedFiles;
this.ocFileListFragmentInterface = ocFileListFragmentInterface;
this.activity = activity;
this.preferences = preferences;
Expand Down Expand Up @@ -412,6 +417,7 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
);
}
case VIEW_TYPE_HEADER -> {
// TODO add height if recommended files is empty
ListHeaderBinding binding = ListHeaderBinding.inflate(
LayoutInflater.from(parent.getContext()),
parent,
Expand All @@ -431,61 +437,20 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
ocFileListFragmentInterface.isLoading() ? View.VISIBLE : View.GONE);
} else if (holder instanceof OCFileListHeaderViewHolder headerViewHolder) {
String text = currentDirectory.getRichWorkspace();

final var recommendedFiles = headerViewHolder.getBinding().recommendedFilesRecyclerView;

final LinearLayoutManager layoutManager = new LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false);
recommendedFiles.setLayoutManager(layoutManager);

// TODO use actual data
ArrayList<Recommendation> mockData = new ArrayList<>(Arrays.asList(
new Recommendation(
2124L,
System.currentTimeMillis(),
"Document1",
"/documents",
"pdf",
"application/pdf",
true,
"Recently opened"
),
new Recommendation(
2130L,
System.currentTimeMillis() - 3600000,
"Image1",
"/pictures",
"jpg",
"image/jpeg",
true,
"Frequently viewed"
),
new Recommendation(
2131L,
System.currentTimeMillis() - 7200000,
"Presentation1",
"/presentations",
"pptx",
"application/vnd.ms-powerpoint",
false,
"Shared with you"
),
new Recommendation(
2126L,
System.currentTimeMillis() - 7200000,
"Presentation1",
"/presentations",
"pptx",
"application/vnd.ms-powerpoint",
false,
"Shared with you"
))
);

final var adapter = new RecommendedFilesAdapter(activity, mockData, ocFileListDelegate, this, mStorageManager);
recommendedFiles.setAdapter(adapter);

PreviewTextFragment.setText(headerViewHolder.getHeaderText(), text, null, activity, true, true, viewThemeUtils);
headerViewHolder.getHeaderView().setOnClickListener(v -> ocFileListFragmentInterface.onHeaderClicked());

ViewExtensionsKt.setVisibleIf(headerViewHolder.getBinding().recommendedFilesLayout, !recommendedFiles.isEmpty());

if (!recommendedFiles.isEmpty()) {
final var recommendedFilesRecyclerView = headerViewHolder.getBinding().recommendedFilesRecyclerView;

final LinearLayoutManager layoutManager = new LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false);
recommendedFilesRecyclerView.setLayoutManager(layoutManager);

final var adapter = new RecommendedFilesAdapter(activity, recommendedFiles, ocFileListDelegate, this, mStorageManager);
recommendedFilesRecyclerView.setAdapter(adapter);
}
} else {
ListViewHolder gridViewHolder = (ListViewHolder) holder;
OCFile file = getItem(position);
Expand Down Expand Up @@ -817,13 +782,15 @@ public boolean shouldShowHeader() {
return false;
}

// TODO add or condition for recommended files
if (!recommendedFiles.isEmpty()) {
return true;
}

if (currentDirectory.getRichWorkspace() == null) {
return false;
}

return !TextUtils.isEmpty(currentDirectory.getRichWorkspace().trim()) || true;
return !TextUtils.isEmpty(currentDirectory.getRichWorkspace().trim());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,12 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.nextcloud.android.lib.resources.recommendations.Recommendation
import com.owncloud.android.databinding.RecommendedFilesListItemBinding
import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.utils.DisplayUtils

// TODO delete mock data
data class Recommendation(
val id: Long,
val timestamp: Long,
val name: String,
val directory: String,
val extension: String,
val mimeType: String,
val hasPreview: Boolean,
val reason: String
)

class RecommendedFilesAdapter(
private val context: Context,
private val recommendations: List<Recommendation>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package com.owncloud.android.ui.fragment;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
Expand All @@ -41,6 +42,8 @@
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.nextcloud.android.lib.resources.files.ToggleFileLockRemoteOperation;
import com.nextcloud.android.lib.resources.recommendations.GetRecommendationsRemoteOperation;
import com.nextcloud.android.lib.resources.recommendations.Recommendation;
import com.nextcloud.android.lib.richWorkspace.RichWorkspaceDirectEditingRemoteOperation;
import com.nextcloud.client.account.User;
import com.nextcloud.client.account.UserAccountManager;
Expand Down Expand Up @@ -72,6 +75,8 @@
import com.owncloud.android.datamodel.e2e.v2.decrypted.DecryptedFolderMetadataFile;
import com.owncloud.android.lib.common.Creator;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
Expand Down Expand Up @@ -151,6 +156,7 @@
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import kotlin.collections.CollectionsKt;

import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;
import static com.owncloud.android.ui.dialog.setupEncryption.SetupEncryptionDialogFragment.SETUP_ENCRYPTION_DIALOG_TAG;
Expand Down Expand Up @@ -249,6 +255,7 @@ protected enum MenuItemAddRemove {
protected MenuItemAddRemove menuItemAddRemoveValue = MenuItemAddRemove.ADD_GRID_AND_SORT_WITH_SEARCH;

private List<MenuItem> mOriginalMenuItems = new ArrayList<>();
private ArrayList<Recommendation> recommendedFiles = new ArrayList<>();

@Override
public void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -383,7 +390,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
mOnlyFoldersClickable = args != null && args.getBoolean(ARG_ONLY_FOLDERS_CLICKABLE, false);
mFileSelectable = args != null && args.getBoolean(ARG_FILE_SELECTABLE, false);
mLimitToMimeType = args != null ? args.getString(ARG_MIMETYPE, "") : "";

fetchRecommendedFiles();
setAdapter(args);

mHideFab = args != null && args.getBoolean(ARG_HIDE_FAB, false);
Expand Down Expand Up @@ -432,6 +439,29 @@ public void onActivityCreated(Bundle savedInstanceState) {
listDirectory(MainApp.isOnlyOnDevice(), false);
}


private void fetchRecommendedFiles() {
new Thread(() -> {{
try {
User user = accountManager.getUser();
final var client = OwnCloudClientFactory.createNextcloudClient(user.toPlatformAccount(), requireActivity());
final var result = new GetRecommendationsRemoteOperation().execute(client);
if (result.isSuccess()) {
recommendedFiles.addAll(result.getResultData());
requireActivity().runOnUiThread(new Runnable() {
@SuppressLint("NotifyDataSetChanged")
@Override
public void run() {
mAdapter.notifyDataSetChanged();
}
});
}
} catch (Exception e) {
Log_OC.d(TAG,"Error caught at fetchRecommendedFiles");
}
}}).start();
}

protected void setAdapter(Bundle args) {
boolean hideItemOptions = args != null && args.getBoolean(ARG_HIDE_ITEM_OPTIONS, false);

Expand All @@ -444,7 +474,8 @@ protected void setAdapter(Bundle args) {
this,
hideItemOptions,
isGridViewPreferred(mFile),
viewThemeUtils
viewThemeUtils,
recommendedFiles
);

setRecyclerViewAdapter(mAdapter);
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
buildscript {
ext {
androidLibraryVersion ="638326e14bc234ca3285852af461d41e6e08d1aa"
androidLibraryVersion ="dd0b8a84fc"
androidPluginVersion = '8.7.3'
androidxMediaVersion = '1.4.1'
androidxTestVersion = "1.6.1"
Expand Down
8 changes: 8 additions & 0 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7954,6 +7954,14 @@
<sha256 value="af2c66e6fa0f282bb91b53849ff2af8aba66ed301269aa9a71783af49a0e99f4" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="dd0b8a84fc">
<artifact name="android-library-dd0b8a84fc.aar">
<sha256 value="a2bd9f25189bfcc2d4cae95f5b2938f9b0ca78235103221cb9dd6c06ffd632e2" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
<artifact name="android-library-dd0b8a84fc.module">
<sha256 value="92391c04c2f28b067d81097926d23318830e820ba5338cbb184b77bc019cedba" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="e7a13d03c1e7549a301edb8b4b58d1c5dda84123">
<artifact name="android-library-e7a13d03c1e7549a301edb8b4b58d1c5dda84123.aar">
<sha256 value="57ab4fd7c922875a7e0b5feac20aa27ab5df0fd3b4e042f92ed727c0b6316e81" origin="Generated by Gradle" reason="Artifact is not signed"/>
Expand Down

0 comments on commit dce1b61

Please sign in to comment.