mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-12-26 13:38:59 +00:00
Internal users / groups references (@) are now supported
This commit is contained in:
parent
50ccebfc91
commit
9cf7e86ac8
@ -0,0 +1,11 @@
|
||||
package org.communiquons.android.comunic.client.data.enums;
|
||||
|
||||
/**
|
||||
* Kinds of virtual directory
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
public enum VirtualDirectoryType {
|
||||
USER,
|
||||
GROUP
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package org.communiquons.android.comunic.client.data.helpers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.communiquons.android.comunic.client.data.enums.VirtualDirectoryType;
|
||||
import org.communiquons.android.comunic.client.data.models.APIRequest;
|
||||
import org.communiquons.android.comunic.client.data.models.APIResponse;
|
||||
import org.communiquons.android.comunic.client.data.models.VirtualDirectory;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Virtual directory helper
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
public class VirtualDirectoryHelper extends BaseHelper {
|
||||
|
||||
public VirtualDirectoryHelper(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the information associated with a directory
|
||||
*
|
||||
* @param directory The directory to find
|
||||
* @return Information about the directory / null in case of failure
|
||||
*/
|
||||
@Nullable
|
||||
public VirtualDirectory find(String directory){
|
||||
|
||||
APIRequest request = new APIRequest(getContext(), "virtualDirectory/find");
|
||||
request.addString("directory", directory);
|
||||
|
||||
try {
|
||||
APIResponse response = new APIRequestHelper().exec(request);
|
||||
if(response.getResponse_code() != 200) return null;
|
||||
return APIToVirtualDirectory(response.getJSONObject());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn an API entry into a VirtualDirectory object
|
||||
*
|
||||
* @param obj The object to parse
|
||||
* @return Generated VirtualDirectory object
|
||||
* @throws JSONException in case of failure
|
||||
*/
|
||||
private static VirtualDirectory APIToVirtualDirectory(JSONObject obj) throws JSONException {
|
||||
VirtualDirectory virtualDirectory = new VirtualDirectory();
|
||||
virtualDirectory.setKind(StringToVirtualDirectoryType(obj.getString("kind")));
|
||||
virtualDirectory.setId(obj.getInt("id"));
|
||||
return virtualDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a string into a virtual directory type
|
||||
*
|
||||
* @param string The string to convert
|
||||
* @return Matching value in enum
|
||||
*/
|
||||
private static VirtualDirectoryType StringToVirtualDirectoryType(String string) {
|
||||
switch (string){
|
||||
case "user":
|
||||
return VirtualDirectoryType.USER;
|
||||
|
||||
case "group":
|
||||
return VirtualDirectoryType.GROUP;
|
||||
}
|
||||
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package org.communiquons.android.comunic.client.data.models;
|
||||
|
||||
import org.communiquons.android.comunic.client.data.enums.VirtualDirectoryType;
|
||||
|
||||
/**
|
||||
* Virtual directory information
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
public class VirtualDirectory {
|
||||
|
||||
//Private fields
|
||||
private VirtualDirectoryType kind;
|
||||
private int id;
|
||||
|
||||
public VirtualDirectoryType getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
public void setKind(VirtualDirectoryType kind) {
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
@ -13,7 +13,6 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
@ -24,15 +23,19 @@ import android.widget.Toast;
|
||||
import org.communiquons.android.comunic.client.BuildConfig;
|
||||
import org.communiquons.android.comunic.client.R;
|
||||
import org.communiquons.android.comunic.client.crashreporter.CrashReporter;
|
||||
import org.communiquons.android.comunic.client.data.enums.VirtualDirectoryType;
|
||||
import org.communiquons.android.comunic.client.data.helpers.APIRequestHelper;
|
||||
import org.communiquons.android.comunic.client.data.helpers.AccountHelper;
|
||||
import org.communiquons.android.comunic.client.data.helpers.ConversationsListHelper;
|
||||
import org.communiquons.android.comunic.client.data.helpers.DatabaseHelper;
|
||||
import org.communiquons.android.comunic.client.data.helpers.DebugHelper;
|
||||
import org.communiquons.android.comunic.client.data.models.NotificationsCount;
|
||||
import org.communiquons.android.comunic.client.data.models.VirtualDirectory;
|
||||
import org.communiquons.android.comunic.client.data.runnables.FriendRefreshLoopRunnable;
|
||||
import org.communiquons.android.comunic.client.data.services.NotificationsService;
|
||||
import org.communiquons.android.comunic.client.data.utils.PreferencesUtils;
|
||||
import org.communiquons.android.comunic.client.ui.asynctasks.FindVirtualDirectoryTask;
|
||||
import org.communiquons.android.comunic.client.ui.asynctasks.SafeAsyncTask;
|
||||
import org.communiquons.android.comunic.client.ui.fragments.ConversationFragment;
|
||||
import org.communiquons.android.comunic.client.ui.fragments.ConversationsListFragment;
|
||||
import org.communiquons.android.comunic.client.ui.fragments.FriendsListFragment;
|
||||
@ -91,6 +94,11 @@ public class MainActivity extends BaseActivity implements
|
||||
*/
|
||||
private NavigationBar mNavBar;
|
||||
|
||||
/**
|
||||
* Tasks
|
||||
*/
|
||||
private FindVirtualDirectoryTask mFindVirtualDirectoryTask;
|
||||
|
||||
/**
|
||||
* Broadcast receiver
|
||||
*/
|
||||
@ -197,9 +205,12 @@ public class MainActivity extends BaseActivity implements
|
||||
friendsListRefreshRunnable.interrupt();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
|
||||
|
||||
unsetFindVirtualDirectoryTask();
|
||||
}
|
||||
|
||||
/**
|
||||
* Activity context menu
|
||||
@ -421,6 +432,70 @@ public class MainActivity extends BaseActivity implements
|
||||
((MainActivity)activity).getSupportFragmentManager().popBackStack();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Follow a tag to open it
|
||||
*
|
||||
* @param activity Activity object
|
||||
* @param tag The tag to follow
|
||||
*/
|
||||
public static void FollowTag(@NonNull Activity activity, String tag){
|
||||
if(!(activity instanceof MainActivity))
|
||||
throw new RuntimeException("Need a MainActivity!");
|
||||
|
||||
((MainActivity)activity).followTag(tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset FindVirtualDirectoryTask callback in order to prevent memory leaks
|
||||
*/
|
||||
private void unsetFindVirtualDirectoryTask(){
|
||||
if(mFindVirtualDirectoryTask != null)
|
||||
mFindVirtualDirectoryTask.setOnPostExecuteListener(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Follow a tag to open it
|
||||
*
|
||||
* @param tag The tag to find
|
||||
*/
|
||||
public void followTag(String tag){
|
||||
final AlertDialog dialog = UiUtils.create_loading_dialog(this);
|
||||
|
||||
unsetFindVirtualDirectoryTask();
|
||||
mFindVirtualDirectoryTask = new FindVirtualDirectoryTask(this);
|
||||
mFindVirtualDirectoryTask.setOnPostExecuteListener(new SafeAsyncTask.OnPostExecuteListener<VirtualDirectory>() {
|
||||
@Override
|
||||
public void OnPostExecute(VirtualDirectory virtualDirectory) {
|
||||
dialog.dismiss();
|
||||
openDirectory(virtualDirectory);
|
||||
}
|
||||
});
|
||||
mFindVirtualDirectoryTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, tag);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a directory
|
||||
*
|
||||
* @param directory The directory to open
|
||||
*/
|
||||
public void openDirectory(@Nullable VirtualDirectory directory){
|
||||
if(directory == null){
|
||||
Toast.makeText(this, R.string.err_find_tag, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (directory.getKind() == VirtualDirectoryType.GROUP){
|
||||
Toast.makeText(this, R.string.err_groups_not_supported,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
else if(directory.getKind() == VirtualDirectoryType.USER){
|
||||
openUserPage(directory.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the friends list fragment
|
||||
*/
|
||||
|
@ -0,0 +1,22 @@
|
||||
package org.communiquons.android.comunic.client.ui.asynctasks;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.communiquons.android.comunic.client.data.helpers.VirtualDirectoryHelper;
|
||||
import org.communiquons.android.comunic.client.data.models.VirtualDirectory;
|
||||
|
||||
/**
|
||||
* Find a virtual directory task
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
public class FindVirtualDirectoryTask extends SafeAsyncTask<String, Void, VirtualDirectory> {
|
||||
public FindVirtualDirectoryTask(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected VirtualDirectory doInBackground(String... strings) {
|
||||
return new VirtualDirectoryHelper(getContext()).find(strings[0]);
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import org.communiquons.android.comunic.client.data.utils.StringsUtils;
|
||||
import org.communiquons.android.comunic.client.ui.activities.MainActivity;
|
||||
import org.communiquons.android.comunic.client.ui.utils.UiUtils;
|
||||
|
||||
/**
|
||||
@ -76,7 +77,7 @@ public class ContentTextView extends android.support.v7.widget.AppCompatTextView
|
||||
int pos = 0;
|
||||
for (String part : parts) {
|
||||
|
||||
//Mark it as URL
|
||||
//Process it as URL if possible
|
||||
if (StringsUtils.isURL(part)) {
|
||||
|
||||
ClickableSpan clickableSpan = new URLClickableSpan(part);
|
||||
@ -85,6 +86,12 @@ public class ContentTextView extends android.support.v7.widget.AppCompatTextView
|
||||
|
||||
}
|
||||
|
||||
else if(part.length() > 0 && part.charAt(0) == '@'){
|
||||
ClickableSpan clickableSpan = new TAGClickableSpan(part);
|
||||
ssb.setSpan(clickableSpan, pos, pos + part.length(),
|
||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
|
||||
pos += part.length() + 1;
|
||||
|
||||
}
|
||||
@ -123,4 +130,21 @@ public class ContentTextView extends android.support.v7.widget.AppCompatTextView
|
||||
getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(mURL)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clickable span for tag
|
||||
*/
|
||||
private class TAGClickableSpan extends BaseClickableSpan {
|
||||
|
||||
private String mTag;
|
||||
|
||||
private TAGClickableSpan(String tag){
|
||||
mTag = tag.substring(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View widget) {
|
||||
MainActivity.FollowTag(getActivity(), mTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -289,4 +289,6 @@
|
||||
<string name="array_authenticated_users">Les utilisateurs connectés à Comunic</string>
|
||||
<string name="array_friends_only">Uniquement mes amis</string>
|
||||
<string name="err_update_account_image_visibility">Une erreur a survenu lors de la mise à jour du niveau de visibilité de l\'image de compte !</string>
|
||||
<string name="err_find_tag">Le tag spécifié n\'a pas été trouvé !</string>
|
||||
<string name="err_groups_not_supported">Les groupes ne sont pas encore supportés sur l\'application Android…</string>
|
||||
</resources>
|
@ -288,4 +288,6 @@
|
||||
<string name="array_authenticated_users">Authenticated users</string>
|
||||
<string name="array_friends_only">Friends only</string>
|
||||
<string name="err_update_account_image_visibility">Could not update account image visibility level!</string>
|
||||
<string name="err_find_tag">Could not find requested tag!</string>
|
||||
<string name="err_groups_not_supported">Groups are not supported yet by the Android application!</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user