Implement dragging to move profiles
This commit is contained in:
@@ -64,6 +64,9 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
|
||||
profile.udpdns = oldProfile.udpdns
|
||||
case _ =>
|
||||
}
|
||||
val last = dbHelper.profileDao.queryRaw(dbHelper.profileDao.queryBuilder.selectRaw("MAX(userOrder)")
|
||||
.prepareStatementString).getFirstResult
|
||||
if (last != null && last.length == 1) profile.userOrder = last(0).toInt + 1
|
||||
dbHelper.profileDao.createOrUpdate(profile)
|
||||
if (profileAddedListener != null) profileAddedListener(profile)
|
||||
profile
|
||||
@@ -109,10 +112,20 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
|
||||
}
|
||||
}
|
||||
|
||||
def getFirstProfile = {
|
||||
try {
|
||||
Option(dbHelper.profileDao.query(dbHelper.profileDao.queryBuilder.limit(1L).prepare).get(0))
|
||||
} catch {
|
||||
case ex: Exception =>
|
||||
Log.e(Shadowsocks.TAG, "getAllProfiles", ex)
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
def getAllProfiles: Option[List[Profile]] = {
|
||||
try {
|
||||
import scala.collection.JavaConversions._
|
||||
Option(dbHelper.profileDao.queryForAll().toList)
|
||||
Option(dbHelper.profileDao.query(dbHelper.profileDao.queryBuilder.orderBy("userOrder", true).prepare).toList)
|
||||
} catch {
|
||||
case ex: Exception =>
|
||||
Log.e(Shadowsocks.TAG, "getAllProfiles", ex)
|
||||
|
||||
Reference in New Issue
Block a user