{"id":13751351,"url":"https://github.com/timroes/SwipeToDismissUndoList","last_synced_at":"2025-05-09T18:31:19.278Z","repository":{"id":6860135,"uuid":"8108978","full_name":"timroes/SwipeToDismissUndoList","owner":"timroes","description":"An Android library to enable swipe to dismiss and undo functionality on ListViews.","archived":false,"fork":false,"pushed_at":"2013-09-23T18:55:09.000Z","size":306,"stargazers_count":248,"open_issues_count":10,"forks_count":72,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-04-20T11:17:00.417Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/timroes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-02-09T11:26:57.000Z","updated_at":"2025-02-08T19:23:43.000Z","dependencies_parsed_at":"2022-07-11T00:46:29.988Z","dependency_job_id":null,"html_url":"https://github.com/timroes/SwipeToDismissUndoList","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timroes%2FSwipeToDismissUndoList","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timroes%2FSwipeToDismissUndoList/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timroes%2FSwipeToDismissUndoList/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timroes%2FSwipeToDismissUndoList/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timroes","download_url":"https://codeload.github.com/timroes/SwipeToDismissUndoList/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253303024,"owners_count":21886873,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T09:00:42.821Z","updated_at":"2025-05-09T18:31:18.770Z","avatar_url":"https://github.com/timroes.png","language":"Java","funding_links":[],"categories":["第一部分 个性化控件(View)"],"sub_categories":[],"readme":"SwipeToDismissUndoList\n=======================\n\n_**This library is deprecated in favor of [EnhancedListView](https://github.com/timroes/EnhancedListView). I won't fix any bugs on this library anymore.**_\n\nThe SwipeToDismissUndoList is a library to add swipe to dismiss functionality to\na `ListView` and undo deletions again. The lib is based on \n[Jake Wharton's SwipeToDismissNOA](https://github.com/JakeWharton/SwipeToDismissNOA)\nthat is based on [Roman Nurik's SwipeToDismiss sample](https://gist.github.com/romannurik/2980593).\n\nThe code is licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0).\n\nYou can view a demonstration of this lib in the [Demonstration App](https://play.google.com/store/apps/details?id=de.timroes.swipetodismiss.demo).\nThe source code of this demonstration app can be found in the [SwipteToDismissUndoDemo](https://github.com/timroes/SwipeToDismissUndoDemo) project.\n\nChanges\n-------\n\n*2013-05-28* Introduced `setSwipeDirection` and improved detection of swipes.\n\n*2013-05-13* Use `AbsListView` instead of `ListView` to make this library also available for GridViews\n\n**Changes required:** You need to change the parameter in the `onDismiss` method to `AbsListView` (see below).\n\n*2013-03-22* Added minimum SDK version to manifest\n\n*2013-02-24* Properly discard undo items (BUG FIX)\n\nUsage\n-----\n\n[Add this project](http://developer.android.com/tools/projects/projects-cmdline.html#ReferencingLibraryProject)\nas an Android library to your project. The project should work from API level 3 upwards. If you find\nthat this isn't true (might be, that I missed some newer methods), please inform me about that :)\n\nTo use the list create a regular `ListView` (e.g. via a `ListActivity`) and wrap\nit up in the `SwipeDismissList` of this lib:\n\n```java\nListView listView = // ... (findById or getListView)\nSwipeDismissList.OnDismissCallback callback = // .. see below\nUndoMode mode = // .. see below\nSwipeDismissList swipeList = new SwipeDismissList(listView, callback, mode);\n```\n\nYou would normally want to do that in your `onCreate` method.\n\n## OnDismissCallback\n\nThe second parameter to the constructor of `SwipeDismissList` is an `OnDismissCallback`.\nYou must implement that, to handle the deletion of elements:\n\n```java\nSwipeDismissList.OnDismissCallback callback = new SwipeDismissList.OnDismissCallback() {\n\tpublic SwipeDismissList.Undoable onDismiss(ListView listView, int position) {\n\t\t// Delete the item from your adapter (sample code):\n\t\tfinal String itemToDelete = mAdapter.get(position);\n\t\tmAdapter.remove(itemToDelete);\n\t\treturn null;\n\t}\n}\n```\n\nIf you return `null` from the `onDismiss` method, your deletion won't be undoable.\nTo make your deletion undoable, you must return a valid `Undoable` (implementing \nat least its `undo` method), that restores the element again:\n\n```java\nSwipeDismissList.OnDismissCallback callback = new SwipeDismissList.OnDismissCallback() {\n\tpublic SwipeDismissList.Undoable onDismiss(AbsListView listView, final int position) {\n\t\t// Delete the item from your adapter (sample code):\n\t\tfinal String itemToDelete = mAdapter.get(position);\n\t\tmAdapter.remove(itemToDelete);\n\t\treturn new SwipeDismissList.Undoable() {\n\t\t\tpublic void undo() {\n\t\t\t\t// Return the item at its previous position again\n\t\t\t\tmAdapter.insert(itemToDelete, position);\n\t\t\t}\n\t\t};\n\t}\n}\n```\n\nYou can override `getTitle` in the `Undoable` to provide an individual title for \nthe item, that has been deleted. That title will be shown beside the undo button\nin the popup. If you don't override that method (or it returns `null`) the default\ndeletion message will be shown in the popup. You can change this message with\n`SwipeDismissList.setUndoString(String)`.\n\nYou can return `null` from the `onDismiss` method in general to disable undo on the \nlist or just on special items, you don't want (or cannot) undo.\n\n### Notification about final delete\n\nIf you want to get notified when the user doesn't have a chance to make the undo anymore,\nmeaning the popup dialog vanished (see below), just override the `Undoable.discard()`\nmethod in your `Undoable`. This will be called as soon as the popup dialog vanishes.\nYou can e.g. really delete items from the database in that callback, that was just hidden\nbeforehand.\n\nIf you implement the discard method you need to call `SwipeDismissList.discardUndo()` in\nthe `onStop` method of your Activity. (See also [Leaky Popup](#leaky-popup) below). Otherwise\nsome items might not receive the `discard` call, when e.g. the device is rotated.\n\n### Complete onDismissCallback example\n\nAn (pseudo) example of a complete `OnDismissCallback`:\n\n```java\nSwipeDismissList.OnDismissCallback callback = new SwipeDismissList.OnDismissCallback() {\n\t// Gets called whenever the user deletes an item.\n\tpublic SwipeDismissList.Undoable onDismiss(AbsListView listView, final int position) {\n\t\t// Get your item from the adapter (mAdapter being an adapter for MyItem objects)\n\t\tfinal MyItem deletedItem = mAdapter.getItem(position);\n\t\t// Delete item from adapter\n\t\tmAdapter.remove(deletedItem);\n\t\t// Return an Undoable implementing every method\n\t\treturn new SwipeDismissList.Undoable() {\n\n\t\t\t// Method is called when user undoes this deletion\n\t\t\tpublic void undo() {\n\t\t\t\t// Reinsert item to list\n\t\t\t\tmAdapter.insert(deletedItem, position)\n\t\t\t}\n\t\t\t\n\t\t\t// Return an undo message for that item\n\t\t\tpublic String getTitle() {\n\t\t\t\treturn deletedItem.toString() + \" deleted\";\n\t\t\t}\n\n\t\t\t// Called when user cannot undo the action anymore\n\t\t\tpublic void discard() {\n\t\t\t\t// Use this place to e.g. delete the item from database\n\t\t\t\tfinallyDeleteFromSomeStorage(deletedItem);\n\t\t\t}\n\t\t};\n\t}\n};\n```\n\n## setAutoHideDelay\n\nThe undo popup will be hidden automatically after some time, after the user has\ntouched the screen after the deletion. The delay until it will hide is by default\n5 seconds. You can change that value with the `setAutoHideDelay(int)` method,\nthat takes a new delay in milliseconds. \n\n## setSwipeDirection\n\nBy default the user can swipe an item left or right to delete it. With this method\nyou can limit it to the left or right side. See the Javadoc of `setSwipeDirection`\nand `SwipeDismissList.SwipeDirection` for further information.\n\n## UndoMode\n\nThe undo list can handle multiple undos in three different ways. You define the way\nwith the third constructor parameter. If you don't pass in an argument, the default\nmode will be `SwipeDismissList.UndoMode.SINGLE_UNDO`.\n\n### SwipeDismissList.UndoMode.SINGLE_UNDO\n\nOnly the last deletion can be undone. As soon as the user deletes another item\nfrom the list, this will be undoable, but the previous won't be anymore.\n\n### SwipeDismissList.UndoMode.MULTI_UNDO\n\nThis mode is a multilevel undo. When the user deletes an item, while there is\nstill the undo popup shown for a previous deleted one, both items will be saved\nfor undo. Pressing now undo will undo the last deletion. Pressing undo after that\nthe deletion that has done before, and so on ...\n\nAs soon as the undo popup vanishes all stored undos will be discarded.\n\nBy default the undo popup shows a message with the amount of deleted items in this\nmode. You can change this message with the `setUndoMultipleString(String)`.\nThis message can contain one placeholder (`%d`) that will be filled with the\namount of stored undos. \n\nIf you pass `null` to that method, the undo popup\nwill always show the individual message (returned by `Undoable.getTitle()`) for\nthe last deletion (the one that will be undone, by a click on undo). If there is\nno individual message for an `Undoable` the default message (`setUndoString(String)`)\nwill be shown instead.\n\n### SwipeDismissList.UndoMode.COLLAPSE_UNDO\n\nThis mode collapsed multiple undos into one. When the user deletes an item, while\nan undo popup is already shown, the new undo is stored. From now on the user sees\nan \"Undo all\" instead of \"Undo\" button. A click on that will undo all stored deletions\nat once.\n\nIf the popup vanished (due to the auto hide delay passed) all stored undos will be\ndiscarded.\n\nYou can again use `setUndoMultipleString(String)` to set an individual message.\nAlso passig `null` is possible, but doesn't make too much sense in that case, since\nthe user will only see the last undo messgae, but all deletions will be undone.\n\n## Customizing and Internationalization\n\nIf you want to customize the look and feel, just modify the resources as you like.\n\nYou can internationalize the \"Undo\" and \"Undo all\" string, in your own resources\nby adding a string for the name \"undo\" and one for \"undoall\". This library only provides\nthe english translation.\n\nYou can pause the dismiss behavior of the list for some time by using the `setEnabled(boolean)`\nmethod on the `SwipeDismissList`.\n\nBugs\n----\n\nFor bugs and feature requests please use the GitHub issue tracker. I haven't limited\nthe library to any android api versions, but it might be, that it doesn't work on \nvery old versions, so please feel free to tell me via an issue, I will then try to fix it.\n\n### Leaky Popup\n\nWhen the popup is shown and the device is rotate, it causes an exception to be thrown.\nThis is nothing really bad, but you can (and should) prevent that exception by calling \n`SwipeDismissList.discardUndo()` in the `onStop` method of your activity.\n\nIf you have implemented the `discard` method (see [above](#notification-about-final-delete)) you \n*MUST* call this method.\n\n\nContact\n-------\n\nFor other questions or help, you can find contact data on [my page](http://www.timroes.de)\nor you will find me often in #android-dev on irc.freenode.net.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimroes%2FSwipeToDismissUndoList","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimroes%2FSwipeToDismissUndoList","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimroes%2FSwipeToDismissUndoList/lists"}