ankidroid / Anki-Android

AnkiDroid: Anki flashcards on Android. Your secret trick to achieve superhuman information retention.
GNU General Public License v3.0
8.38k stars 2.18k forks source link

Add support for profiles #2545

Open hssm opened 9 years ago

hssm commented 9 years ago

Parallel builds simulate profiles. They don't auto-update, but you can find them:

edited by @david-allison


Originally reported on Google Code with ID 1643

Anki 2.0 supports having different profiles for different users.
This also allows a user to split their decks between different collections.

I built a prototype of this and it seems quite simple.
The prototype is based on using different preference files.

Reported by flerda on 2013-01-26 01:18:26

mikehardy commented 2 years ago

I agree real profile support is important - and you are right David it is literally the reason I started hacking on this app at all hahaha. One of these days it'll get there in the meantime I'm glad you enjoy the hacky but usable parallel install workaround I made. I do use it myself (for my child's collection) so it's guaranteed to be available until real profile support comes in. Cheers

minustimesplus commented 10 months ago

I agree real profile support is important - and you are right David it is literally the reason I started hacking on this app at all hahaha. One of these days it'll get there in the meantime I'm glad you enjoy the hacky but usable parallel install workaround I made. I do use it myself (for my child's collection) so it's guaranteed to be available until real profile support comes in. Cheers

Hi! Any updates on this?

fluxens commented 8 months ago

Can we start a bounty for this? I am wiling to chip in $200.

david-allison commented 8 months ago

I'd be willing to take this on, I was planning for it some time in the new year anyway

david-allison commented 8 months ago

Draft of my thoughts:

EDITS in bold

Anki's screen ![Screenshot 2024-01-02 at 13 15 03](https://github.com/ankidroid/Anki-Android/assets/62114487/3b4f2566-1c40-44db-8d8f-6d96a008c485)

Functionality

Defaults

Unknown

Constraints

BrayanDSO commented 8 months ago

How do we handle WebView cookies Specifically: Shared Decks -> AnkiWeb login

Share it, I guess

How do we handle app shortcuts

Maybe add the profile name to each one? (I have no idea if that is possible) -> Add (David), Study (Arthur)

Profile names may contain special characters. Should the name map to a folder name?

Mimic Anki desktop behavior or allow any characters in the profile name but strip the unallowed in the folder name

Our current folder is AnkiDroid

For app private builds, doesn't seem to be a problem

For full builds, ideally the profile should be in AnkiDroid/profile name but AnkiDroid/ already has the collection. The easiest solution I see is keeping the old AnkiDroid/ folder and if the user tries to create a new profile, default it to a new directory called AnkiDroid profiles or some better name (ideally one that doesn't need to be localized). For new installs, we can default to this new folder

david-allison commented 8 months ago

I specifically chose AnkiDroid so we're not writing to the root of com.ichi2.anki/files in the private directory (so AnkiDroid can be the default profile)

For the public directory, AnkiDroid Profiles seems ideal

How do we handle app shortcuts Maybe add the profile name to each one? (I have no idea if that is possible) -> Add (David), Study (Arthur)

I believe this is workable. Our shortcuts are dynamic.



I think we want to isolate the WebView cookies if at all possible

BrayanDSO commented 8 months ago

Widgets: probably 'unsupported' for now and have them tied to the current profile

For the add note widget, I don't suggest any work because it should deprecated when minSdk reaches Nougat and everyone can use shortcuts.

For the reviews shortcut, it needs a redesign so it can have some configurable aspect to distinct it from other instances of it (a color, icon, emoji, text, whatever).

edit: when I say redesign, I mean a whole redesign in appearance, size, etc. It doesn't need to be similar to the current one

I think we want to isolate the WebView cookies if at all possible

Now that I thought a little bit more, I agree

david-allison commented 4 months ago

API 28+: WebView.setDataDirectorySuffix

david-allison commented 4 months ago

Pseudocode

A profile will be of the format:

data class ProfileData(val identifier: String, var name: String) {
    val webViewDataDirectory get() = identifier
    fun preferences(context: Context) = context.getSharedPreferences(
           name = identifier,            
           mode = getDefaultSharedPreferencesMode(),
        )
    fun rename(name: String) = TODO()
    fun select() = TODO()
    fun delete() = TODO("do we also delete data?")
    companion object {
         fun listAll(): List<ProfileData> { }   
    }
}

identifier must NOT contain path separators (setDataDirectorySuffix) Proposal: current unix timestamp in ms


A file containing List<ProfileData> should exist, for use on the Profile Management screen

Realistic options for storage of the ProfileCollection:

  1. in the current SharedPreferences using StringSet + concatenated string
    • As we've done previously
    • Fast
  2. In a new SharedPreferences
    • slightly faster than the above
  3. Jetpack Data Store
    • Strongly Typed
    • Async
    • Slower

TODO:

david-allison commented 2 months ago

I'm not going to have capacity to take this through for the 2.19 series